{"commit":"5b3ccaafe5f939ae3f577bd2529e4297073b3dd1","subject":"Fix previous commit","message":"Fix previous commit\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat,toLowerCase), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\nCACHE_NS_THRESHOLD :== 40000000\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Maybe [String]\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (alwaysUnique,db) = alwaysUniquePredicate db\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True alwaysUnique allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w)\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", (Nothing,0), db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t#! (start,w) = nsTime w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond start Nothing {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond start Nothing (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond start Nothing (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond start Nothing (err InvalidType \"Couldn't parse type\") db w\n\t\t| all isNothing [unify,name,request.typeName,request.className] && isNothing request.using\n\t\t\t= respond start Nothing (err InvalidInput \"Empty query\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond start (Just key) response db w\n\twhere\n\t\trespond :: !Timespec !(Maybe RequestCacheKey) !Response !*CloogleDB !*World ->\n\t\t\t*(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\t\trespond start key r db w\n\t\t#! (end,w) = nsTime w\n\t\t#! duration = 1000000000 * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec\n\t\t#! cache = duration > CACHE_NS_THRESHOLD\n\t\t= (r, (if cache (cacheKey <$> key) Nothing, duration \/ 1000), db, case (cache,key) of\n\t\t\t(True,Just k) -> writeCache LongTerm k r w\n\t\t\t_ -> w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World)\n\treloadCache (db,w)\n\t# (ks,w) = allCacheKeys LongTerm w\n\t= loop ks db w\n\twhere\n\t\tloop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World)\n\t\tloop [] db w = (db,w)\n\t\tloop [k:ks] db w\n\t\t# w = removeFromCache LongTerm k w\n\t\t# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w\n\t\t# db = resetDB db\n\t\t= loop ks db w\n\n\tdoInBackground :: (*a -> *a) *a -> *a\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: MicroSeconds :== Int\n\n:: LogMessage` :== LogMessage (Maybe Request) Response (Maybe CacheKey, MicroSeconds)\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, microseconds :: Int\n\t, request :: Maybe Request\n\t, cachekey :: Maybe String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response (ck,us)) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, microseconds = us\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat,toLowerCase), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\nCACHE_NS_THRESHOLD :== 40000000\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Maybe [String]\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (alwaysUnique,db) = alwaysUniquePredicate db\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True alwaysUnique allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w)\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", (Nothing,0), db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t#! (start,w) = nsTime w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond start Nothing {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond start Nothing (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond start Nothing (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond start Nothing (err InvalidType \"Couldn't parse type\") db w\n\t\t| all isNothing [unify,name,request.typeName,request.className] && isNothing request.unify\n\t\t\t= respond start Nothing (err InvalidInput \"Empty query\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond start (Just key) response db w\n\twhere\n\t\trespond :: !Timespec !(Maybe RequestCacheKey) !Response !*CloogleDB !*World ->\n\t\t\t*(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\t\trespond start key r db w\n\t\t#! (end,w) = nsTime w\n\t\t#! duration = 1000000000 * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec\n\t\t#! cache = duration > CACHE_NS_THRESHOLD\n\t\t= (r, (if cache (cacheKey <$> key) Nothing, duration \/ 1000), db, case (cache,key) of\n\t\t\t(True,Just k) -> writeCache LongTerm k r w\n\t\t\t_ -> w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World)\n\treloadCache (db,w)\n\t# (ks,w) = allCacheKeys LongTerm w\n\t= loop ks db w\n\twhere\n\t\tloop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World)\n\t\tloop [] db w = (db,w)\n\t\tloop [k:ks] db w\n\t\t# w = removeFromCache LongTerm k w\n\t\t# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w\n\t\t# db = resetDB db\n\t\t= loop ks db w\n\n\tdoInBackground :: (*a -> *a) *a -> *a\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: MicroSeconds :== Int\n\n:: LogMessage` :== LogMessage (Maybe Request) Response (Maybe CacheKey, MicroSeconds)\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, microseconds :: Int\n\t, request :: Maybe Request\n\t, cachekey :: Maybe String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response (ck,us)) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, microseconds = us\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"4968b2089584a58852f581912d5d3ca9e5ae4570","subject":"Add documentation for ABC instructions: push_{r_arg_t,t_r_a,t_r_args}","message":"Add documentation for ABC instructions: push_{r_arg_t,t_r_a,t_r_args}\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/Builtin\/ABC.icl","new_file":"backend\/Builtin\/ABC.icl","new_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t, i_push_r_arg_t\n\t, i_push_t_r_a\n\t, i_push_t_r_args\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \" - sep can be either `-` or `:`.\"\n\t\t\t, \" - flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \" - input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t\t, \" - output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t\t, \" - state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \" - `I` for integers\"\n\t\t\t, \" - `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \" - [`Rr`] for reals\"\n\t\t\t, \" - `S` for Clean Strings (`{#Char}`). If used as input type this passes a pointer to the string's length (number of characters). The actual array is at offset 4\/8 (32\/64 bit). If this is used as output type, the C function has to return a pointer to the string's length, followed by the actual string. A copy of the string will be created in the Clean heap, and this copy will be used by Clean. If the string was allocated in C, for example using malloc, it should be deallocated in C when it no longer used, it is not automatically deallocated by Clean.\"\n\t\t\t, \" - `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}}, as the string is not null-terminated). The length (number of characters) is at offset -4\/-8. (32\/64 bit).\"\n\t\t\t, \" - `A` for A-stack elements, which can be:\"\n\t\t\t, \" * `*World`, which is a boxed integer under the hood\"\n\t\t\t, \" * integer or real arrays (`{#Int}` or `{#Real}`). This passes a pointer to the array. The length (number of integers\/reals) is at offset -8\/-16 (32\/64 bit).\"\n\t\t\t, \" - [`OF`] for function pointers\"\n\t\t\t, \" - `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\n\ti_push_r_arg_t =\n\t\t{ zero\n\t\t& aie_instruction = \"push_r_arg_t\"\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Gets the *n*th element from the type string of a record.\"\n\t\t\t, \"The type string is on top of the B-stack; *n* below that.\"\n\t\t\t]\n\t\t}\n\ti_push_t_r_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Push the address of the type string of the referenced record to the B-stack.\"\n\t\t}\n\ti_push_t_r_args =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_args\"\n\t\t, aie_description = \"Pops a record from the A-stack, pushes its members in reversed order to both of the stacks, then pushes the address of the type string to the B-stack.\"\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_n\n\t, d_nu\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_n =\n\t\t{ zero\n\t\t& aie_instruction = \".n\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t, \"\\n\\nThere are some special cases:\\n\\n\"\n\t\t\t, \"- An arity of `-1` is for tuple selectors;\\n\"\n\t\t\t, \"- An arity of `-2` is for indirection nodes;\\n\"\n\t\t\t, \"- An arity of `-3` is for record selectors of basic types;\\n\"\n\t\t\t, \"- An arity of `-4` is for record selectors of non-basic types.\\n\\n\"\n\t\t\t, \"See also {{`.nu`}}.\"\n\t\t\t]\n\t\t}\n\td_nu =\n\t\t{ zero\n\t\t& aie_instruction = \".nu\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels with arguments on the B-stack (otherwise, {{`.n`}} is used).\"\n\t\t\t, \"The first integer is the number of A-stack arguments; the second the number of B-stack arguments.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_a_b\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","old_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \" - sep can be either `-` or `:`.\"\n\t\t\t, \" - flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \" - input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t\t, \" - output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t\t, \" - state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \" - `I` for integers\"\n\t\t\t, \" - `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \" - [`Rr`] for reals\"\n\t\t\t, \" - `S` for Clean Strings (`{#Char}`). If used as input type this passes a pointer to the string's length (number of characters). The actual array is at offset 4\/8 (32\/64 bit). If this is used as output type, the C function has to return a pointer to the string's length, followed by the actual string. A copy of the string will be created in the Clean heap, and this copy will be used by Clean. If the string was allocated in C, for example using malloc, it should be deallocated in C when it no longer used, it is not automatically deallocated by Clean.\"\n\t\t\t, \" - `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}}, as the string is not null-terminated). The length (number of characters) is at offset -4\/-8. (32\/64 bit).\"\n\t\t\t, \" - `A` for A-stack elements, which can be:\"\n\t\t\t, \" * `*World`, which is a boxed integer under the hood\"\n\t\t\t, \" * integer or real arrays (`{#Int}` or `{#Real}`). This passes a pointer to the array. The length (number of integers\/reals) is at offset -8\/-16 (32\/64 bit).\"\n\t\t\t, \" - [`OF`] for function pointers\"\n\t\t\t, \" - `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_n\n\t, d_nu\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_n =\n\t\t{ zero\n\t\t& aie_instruction = \".n\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t, \"\\n\\nThere are some special cases:\\n\\n\"\n\t\t\t, \"- An arity of `-1` is for tuple selectors;\\n\"\n\t\t\t, \"- An arity of `-2` is for indirection nodes;\\n\"\n\t\t\t, \"- An arity of `-3` is for record selectors of basic types;\\n\"\n\t\t\t, \"- An arity of `-4` is for record selectors of non-basic types.\\n\\n\"\n\t\t\t, \"See also {{`.nu`}}.\"\n\t\t\t]\n\t\t}\n\td_nu =\n\t\t{ zero\n\t\t& aie_instruction = \".nu\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels with arguments on the B-stack (otherwise, {{`.n`}} is used).\"\n\t\t\t, \"The first integer is the number of A-stack arguments; the second the number of B-stack arguments.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_a_b\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_t_r_a\"\n\t, \"push_t_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_t\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"a6a4ce4aca9b1b59574ee57b318191d8b7a77663","subject":"Fix runtime error","message":"Fix runtime error\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Tuple\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , libraries :: Maybe ([String], Bool)\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , dcl_line :: Maybe Int\n , distance :: Int\n , builtin :: Maybe Bool\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , recordfield_of :: Maybe String\n , generic_derivations :: Maybe [(String, [LocationResult])]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n , type_instances :: [(String, [String], [LocationResult])]\n , type_derivations :: [(String, [LocationResult])]\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [([String], [LocationResult])]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: LocationResult :== (String, String, Maybe Int)\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = MaybeError Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , libraries = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache request w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err E_NORESULTS \"No results\")\n\t\t\t{ return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\trespond :: Response *World -> *(Response, *World)\n\t\trespond r w = (r, writeCache LongTerm request r w)\n\n\t\tcachePages :: Int Int Response [Result] *World -> *World\n\t\tcachePages _ _ _ [] w = w\n\t\tcachePages 0 _ _ _ w = w\n\t\tcachePages npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { request & page = ((+) i) <$> request.page <|> pure 0 }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n (Location lib mod Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\loc _ _ _ -> toLowerCase (getName loc) == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [([concat (print False t) \\\\ t <- ts], map loc ls)\n\t\t \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,builtin) = case fl of\n\t\t\t(Location l m ln f) = (l, m, f, ln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln _) = (lib, mod, ln)\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg +\n\t\t\tif (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\" + \")\\n\"\n\tmsgToString _ _ = \"\"\n","old_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Tuple\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , libraries :: Maybe ([String], Bool)\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , dcl_line :: Maybe Int\n , distance :: Int\n , builtin :: Maybe Bool\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , recordfield_of :: Maybe String\n , generic_derivations :: Maybe [(String, [LocationResult])]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n , type_instances :: [(String, [String], [LocationResult])]\n , type_derivations :: [(String, [LocationResult])]\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [([String], [LocationResult])]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: LocationResult :== (String, String, Maybe Int)\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = MaybeError Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , libraries = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache request w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err E_NORESULTS \"No results\")\n\t\t\t{ return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\trespond :: Response *World -> *(Response, *World)\n\t\trespond r w = (r, writeCache LongTerm request r w)\n\n\t\tcachePages :: Int Int Response [Result] *World -> *World\n\t\tcachePages _ _ _ [] w = w\n\t\tcachePages 0 _ _ _ w = w\n\t\tcachePages npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { request & page = ((+) i) <$> request.page <|> pure 0 }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n (Location lib mod Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\(Location _ _ _ c`) _ _ _ -> toLowerCase c` == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [([concat (print False t) \\\\ t <- ts], map loc ls)\n\t\t \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,builtin) = case fl of\n\t\t\t(Location l m ln f) = (l, m, f, ln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln _) = (lib, mod, ln)\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg +\n\t\t\tif (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\" + \")\\n\"\n\tmsgToString _ _ = \"\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"ab13a59f07e29cd33b8536f1bbb4fa606760acdb","subject":"Remove debug output","message":"Remove debug output\n","repos":"ErinvanderVeen\/Clone,ErinvanderVeen\/Clone","old_file":"src\/Clone.icl","new_file":"src\/Clone.icl","new_contents":"module Clone\n\nimport Config, BotQueue, Bot, IPC\nimport Data.Maybe, Data.List\nfrom Text.JSON import instance fromString JSONNode\nfrom System._Posix import select_, chdir\nfrom System._Pointer import :: Pointer\nfrom System.Time import ::Timestamp, time, diffTime\nfrom StdListExtensions import foldrSt\nfrom StdFunc import o\nimport StdString, StdInt\n\nStart :: !*World -> ()\nStart world\n# (socket, world) = create_socket world\n# queue = newBotQueue\n# (config, world) = parseConfig world\n# queue = foldr addIfRootBot queue config.bots\n= loop config queue socket world\n\nloop :: Config BotQueue Socket !*World -> ()\nloop config queue socket world\n# (queue, world) = runRequiredBots config queue world\n# (queue, world) = sleepUntilRun config queue socket world\n= loop config queue socket world\n\nsleepUntilRun :: Config BotQueue Socket !*World -> (!BotQueue, !*World)\nsleepUntilRun config queue socket world \n# sleepTime = getWaitTime queue\n| sleepTime == 0 = (queue, world)\n# (startTime, world) = time world\n# (interruptString, world) = wait sleepTime socket world\n\/\/ TODO: Socket can be closed with no content\n| interruptString == \"\" = (mapQueue (\\b -> {b & interval = b.interval - sleepTime}) queue, world)\n# (endTime, world) = time world\n# timeSlept = diffTime endTime startTime\n# queue = mapQueue (\\b -> {b & interval = min 0 (b.interval - timeSlept)}) queue\n# queue = handleInterrupt config interruptString queue\n= sleepUntilRun config queue socket world\n\nhandleInterrupt :: Config String BotQueue -> BotQueue\nhandleInterrupt config interruptString queue\n# node = fromString interruptString\n# bot = toBot node\n= insertBot bot queue\n\nrunRequiredBots :: Config BotQueue !*World -> (!BotQueue, !*World)\nrunRequiredBots config queue world\n# (requiredBots, queue) = allBotsOnZero queue\n# (queue, world) = foldrSt (uncurry o runBotAndChildren config) requiredBots (queue, world)\n| runRequired queue = runRequiredBots config queue world\n| otherwise = (queue, world)\n\nrunBotAndChildren :: Config Bot !BotQueue !*World -> (!BotQueue, !*World)\nrunBotAndChildren config bot queue world\n# (result, world) = runBot bot world\n# queue = addIfRootBot (findBot bot.name config) queue\n| isNothing result = (queue, world)\n# queue = foldr (\\c -> insertBot {findBot c config & input=result}) queue bot.children\n= (queue, world)\nwhere\n\tfindBot :: String Config -> Bot\n\tfindBot name config = fromJust (find (\\b -> b.name == name) config.bots)\n\naddIfRootBot :: Bot BotQueue -> BotQueue\naddIfRootBot bot queue\n| bot.root = insertBot bot queue\n| otherwise = queue\n","old_contents":"module Clone\n\nimport Config, BotQueue, Bot, IPC\nimport Data.Maybe, Data.List\nfrom Text.JSON import instance fromString JSONNode\nfrom System._Posix import select_, chdir\nfrom System._Pointer import :: Pointer\nfrom System.Time import ::Timestamp, time, diffTime\nfrom StdListExtensions import foldrSt\nfrom StdFunc import o\nimport StdString, StdInt\n\nimport StdDebug\n\nStart :: !*World -> ()\nStart world\n# (socket, world) = create_socket world\n# queue = newBotQueue\n# (config, world) = parseConfig world\n# queue = foldr addIfRootBot queue config.bots\n= loop config queue socket world\n\nloop :: Config BotQueue Socket !*World -> ()\nloop config queue socket world\n# (queue, world) = runRequiredBots config queue world\n# (queue, world) = sleepUntilRun config queue socket world\n= loop config queue socket world\n\nsleepUntilRun :: Config BotQueue Socket !*World -> (!BotQueue, !*World)\nsleepUntilRun config queue socket world \n# sleepTime = getWaitTime queue\n| sleepTime == 0 = (queue, world)\n# (startTime, world) = time world\n# (interruptString, world) = wait sleepTime socket world\n| interruptString == \"\" = trace_n \"Sleep completed\" (mapQueue (\\b -> {b & interval = b.interval - sleepTime}) queue, world)\n# (endTime, world) = trace_n \"Interrupted\" time world\n# timeSlept = diffTime endTime startTime\n# queue = mapQueue (\\b -> {b & interval = min 0 (b.interval - timeSlept)}) queue\n# queue = handleInterrupt config interruptString queue\n= sleepUntilRun config queue socket world\n\nhandleInterrupt :: Config String BotQueue -> BotQueue\nhandleInterrupt config interruptString queue\n# node = fromString interruptString\n# bot = toBot node\n= insertBot bot queue\n\nrunRequiredBots :: Config BotQueue !*World -> (!BotQueue, !*World)\nrunRequiredBots config queue world\n# (requiredBots, queue) = allBotsOnZero queue\n# (queue, world) = foldrSt (uncurry o runBotAndChildren config) requiredBots (queue, world)\n| runRequired queue = runRequiredBots config queue world\n| otherwise = (queue, world)\n\nrunBotAndChildren :: Config Bot !BotQueue !*World -> (!BotQueue, !*World)\nrunBotAndChildren config bot queue world\n# (result, world) = runBot bot world\n# queue = addIfRootBot (findBot bot.name config) queue\n| isNothing result = (queue, world)\n# queue = foldr (\\c -> insertBot {findBot c config & input=result}) queue bot.children\n= (queue, world)\nwhere\n\tfindBot :: String Config -> Bot\n\tfindBot name config = fromJust (find (\\b -> b.name == name) config.bots)\n\naddIfRootBot :: Bot BotQueue -> BotQueue\naddIfRootBot bot queue\n| bot.root = insertBot bot queue\n| otherwise = queue\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"fce85599952844aaad4c8af96d7cab3454b0e1d1","subject":"Clean up backend logger","message":"Clean up backend logger\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nimport StdList\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\nfrom StdFunc import const, flip, id, o, seq\nfrom StdMisc import abort, undef\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Tuple\nimport Data.Maybe\nimport System.CommandLine\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase,split),\n\tinstance Text String, instance + String\nimport Text.JSON\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\nimport Cloogle\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\nDEFAULT_INCLUDE_BUILTINS :== True\nDEFAULT_INCLUDE_CORE :== False\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle _ Nothing w = (err CLOOGLE_E_INVALIDINPUT \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey key, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err CLOOGLE_E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions = mbType >>= flip (suggs name) db\n\t\t# w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- mb2list suggestions] w\n\t\t\twith\n\t\t\t\tmb2list Nothing = []; mb2list (Just xs) = xs\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err CLOOGLE_E_NORESULTS \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: Response *World -> *(Response, CacheKey, *World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: RequestCacheKey Int Int Response [Result] *World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page,include_builtins,include_core} db\n\t\t# include_builtins = fromJust (include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t\t# include_core = fromJust (include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t# db = if include_builtins id (filterLocations (not o isBuiltin)) db\n\t\t# db = if include_core id (filterLocations (not o isCore)) db\n\t\t\twith\n\t\t\t\tisCore :: Location -> Bool\n\t\t\t\tisCore (Builtin _) = False\n\t\t\t\tisCore (Location lib mod _ _ _) = case getModule lib mod db of\n\t\t\t\t\tNothing = False\n\t\t\t\t\t(Just b) = b.is_core\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n $ getName loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n $ getName loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n f) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line iclline cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line iclline f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\loc _ _ _ -> toLowerCase (getName loc) == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Search modules\n\t\t# modules = case (mbType, name) of\n\t\t\t(Nothing, Just n) = findModule` (\\_ m _ -> isModNameMatch (size n*2\/3) n m) db\n\t\t\t_ = []\n\t\t# modules = map (makeModuleResult name) modules\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros ++ modules\n\n\tmakeModuleResult :: (Maybe String) (Library, Module, ModuleInfo) -> Result\n\tmakeModuleResult mbName (lib, mod, info)\n\t\t= ModuleResult\n\t\t ( { library = lib\n\t\t , modul = mod\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , distance = modLevenshtein (fromJust mbName) mod\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { module_is_core = info.is_core\n\t\t }\n\t\t )\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line iclline cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" | \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [(map snd ts, map loc ls) \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line iclline t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map snd)) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map snd)) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line iclline m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(s, map loc ls) \\\\ (_,s,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,iclline,builtin) = case fl of\n\t\t\t(Location l m ln iln f) = (l, m, f, ln, iln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 +\n\t\tlevenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodLevenshtein :: String Module -> Int\n\tmodLevenshtein s mod\n\t| s == mod = -100\n\t| isMember s path = length path\n\t| otherwise = levenshtein` s mod\n\twhere path = split \".\" mod\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String !String -> Bool\n\tisNameMatch maxdist n1 name\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: name})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModNameMatch :: !Int !String !Module -> Bool\n\tisModNameMatch maxdist name mod\n\t\t= isNameMatch maxdist name mod || isMember name (split \".\" mod)\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: ![String] Location -> Bool\n\tisLibMatch libs (Location lib _ _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch _ (Builtin _) = True\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln iln _) = (lib, mod, ln, iln)\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received (Just r)) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ mkTime mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ mkTime mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nimport StdList\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\nfrom StdFunc import const, flip, id, o, seq\nfrom StdMisc import abort, undef\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Tuple\nimport Data.Maybe\nimport System.CommandLine\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase,split),\n\tinstance Text String, instance + String\nimport Text.JSON\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\nimport Cloogle\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\nDEFAULT_INCLUDE_BUILTINS :== True\nDEFAULT_INCLUDE_CORE :== False\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle _ Nothing w = (err CLOOGLE_E_INVALIDINPUT \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey key, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err CLOOGLE_E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions = mbType >>= flip (suggs name) db\n\t\t# w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- mb2list suggestions] w\n\t\t\twith\n\t\t\t\tmb2list Nothing = []; mb2list (Just xs) = xs\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err CLOOGLE_E_NORESULTS \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: Response *World -> *(Response, CacheKey, *World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: RequestCacheKey Int Int Response [Result] *World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page,include_builtins,include_core} db\n\t\t# include_builtins = fromJust (include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t\t# include_core = fromJust (include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t# db = if include_builtins id (filterLocations (not o isBuiltin)) db\n\t\t# db = if include_core id (filterLocations (not o isCore)) db\n\t\t\twith\n\t\t\t\tisCore :: Location -> Bool\n\t\t\t\tisCore (Builtin _) = False\n\t\t\t\tisCore (Location lib mod _ _ _) = case getModule lib mod db of\n\t\t\t\t\tNothing = False\n\t\t\t\t\t(Just b) = b.is_core\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n $ getName loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n $ getName loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n f) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line iclline cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line iclline f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\loc _ _ _ -> toLowerCase (getName loc) == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Search modules\n\t\t# modules = case (mbType, name) of\n\t\t\t(Nothing, Just n) = findModule` (\\_ m _ -> isModNameMatch (size n*2\/3) n m) db\n\t\t\t_ = []\n\t\t# modules = map (makeModuleResult name) modules\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros ++ modules\n\n\tmakeModuleResult :: (Maybe String) (Library, Module, ModuleInfo) -> Result\n\tmakeModuleResult mbName (lib, mod, info)\n\t\t= ModuleResult\n\t\t ( { library = lib\n\t\t , modul = mod\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , distance = modLevenshtein (fromJust mbName) mod\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { module_is_core = info.is_core\n\t\t }\n\t\t )\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line iclline cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" | \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [(map snd ts, map loc ls) \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line iclline t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map snd)) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map snd)) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line iclline m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(s, map loc ls) \\\\ (_,s,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,iclline,builtin) = case fl of\n\t\t\t(Location l m ln iln f) = (l, m, f, ln, iln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 +\n\t\tlevenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodLevenshtein :: String Module -> Int\n\tmodLevenshtein s mod\n\t| s == mod = -100\n\t| isMember s path = length path\n\t| otherwise = levenshtein` s mod\n\twhere path = split \".\" mod\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String !String -> Bool\n\tisNameMatch maxdist n1 name\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: name})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModNameMatch :: !Int !String !Module -> Bool\n\tisModNameMatch maxdist name mod\n\t\t= isNameMatch maxdist name mod || isMember name (split \".\" mod)\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: ![String] Location -> Bool\n\tisLibMatch libs (Location lib _ _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch _ (Builtin _) = True\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln iln _) = (lib, mod, ln, iln)\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< msgToString msg mem <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received (Just r)) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmsgToString :: LogMessage` LogMemory -> String\n\tmsgToString (Sent response ck) mem\n\t\t= toString $ toJSON\n\t\t\t{ ip = toString mem.mem_ip\n\t\t\t, time_start = (toString mem.mem_time_start, toInt $ mkTime mem.mem_time_start)\n\t\t\t, time_end = (toString mem.mem_time_end, toInt $ mkTime mem.mem_time_end)\n\t\t\t, request = mem.mem_request\n\t\t\t, cachekey = ck\n\t\t\t, response_code = response.return\n\t\t\t, results = length response.data\n\t\t\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"e137750b76d6920ed64f315f1b6f2503441802f7","subject":"Whoops. Match on JSONObject so that abort message can actually be reached","message":"Whoops. Match on JSONObject so that abort message can actually be reached\n","repos":"ErinvanderVeen\/Clone,ErinvanderVeen\/Clone","old_file":"src\/Config.icl","new_file":"src\/Config.icl","new_contents":"implementation module Config\n\nimport Bot\nimport System.File, Text.JSON, Data.Maybe\nfrom Data.Error import isError, fromOk\nfrom StdMisc import abort\nfrom StdFile import instance FileSystem World\n\nparseConfig :: !*World -> (Config, *World)\nparseConfig w\n# (configString, w) = readConfig w\n# node = fromString configString\n# botsArray = jsonQuery \"bots\" node\n| isNothing botsArray = abort \"Could not find \\\"bots\\\" in config file\"\n# botsArray = fromJSONArray (fromJust botsArray)\n| isNothing botsArray = abort \"Could not get bots array from config file\"\n# botsArray = map toBot (fromJust botsArray)\n# config = { Config | bots = botsArray }\n= (config, w)\nwhere\n\treadConfig :: !*World -> (String, *World)\n\treadConfig w\n\t# (result, w) = readFile \"config\" w\n\t| isError result = abort \"Could not read from config file\"\n\t# result = fromOk result\n\t= (result, w)\n\n\tfromJSONArray :: JSONNode -> Maybe [JSONNode]\n\tfromJSONArray (JSONArray x) = Just x\n\tfromJSONArray _ = Nothing\n\n\ttoBot :: JSONNode -> Bot\n\ttoBot node=:(JSONObject _) = \n\t {Bot | name=fromJust (jsonQuery \"name\" node),\n\t children=fromJust (jsonQuery \"children\" node),\n\t interval=fromJust (jsonQuery \"interval\" node)\n\t }\n\ttoBot _ = abort \"Could not parse bot in config file\"\n","old_contents":"implementation module Config\n\nimport Bot\nimport System.File, Text.JSON, Data.Maybe\nfrom Data.Error import isError, fromOk\nfrom StdMisc import abort\nfrom StdFile import instance FileSystem World\n\nparseConfig :: !*World -> (Config, *World)\nparseConfig w\n# (configString, w) = readConfig w\n# node = fromString configString\n# botsArray = jsonQuery \"bots\" node\n| isNothing botsArray = abort \"Could not find \\\"bots\\\" in config file\"\n# botsArray = fromJSONArray (fromJust botsArray)\n| isNothing botsArray = abort \"Could not get bots array from config file\"\n# botsArray = map toBot (fromJust botsArray)\n# config = { Config | bots = botsArray }\n= (config, w)\nwhere\n\treadConfig :: !*World -> (String, *World)\n\treadConfig w\n\t# (result, w) = readFile \"config\" w\n\t| isError result = abort \"Could not read from config file\"\n\t# result = fromOk result\n\t= (result, w)\n\n\tfromJSONArray :: JSONNode -> Maybe [JSONNode]\n\tfromJSONArray (JSONArray x) = Just x\n\tfromJSONArray _ = Nothing\n\n\ttoBot :: JSONNode -> Bot\n\ttoBot node = {Bot | name=fromJust (jsonQuery \"name\" node),\n\t children=fromJust (jsonQuery \"children\" node),\n\t interval=fromJust (jsonQuery \"interval\" node)\n\t }\n\ttoBot _ = abort \"Could not parse bot in config file\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"07a2d37e49592bcbc29223ef864a20543b6e3121","subject":"underscores are also allowed in usernames...","message":"underscores are also allowed in usernames...\n","repos":"clean-cloogle\/clean-irc","old_file":"IRC.icl","new_file":"IRC.icl","new_contents":"implementation module IRC\n\nimport StdList, StdTuple, StdOverloaded, StdFunc, StdString, StdChar, StdBool\nimport _SystemArray\n\nimport GenPrint\nimport GenIRC\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Either\nimport Data.Maybe\nimport Data.Tuple\nimport Text.Parsers.Simple.Chars\nimport Text.Parsers.Simple.Core\n\nimport StdDebug\n\nfrom Data.Functor import <$>\nfrom Data.Func import $\nfrom StdMisc import undef, abort\nfrom Text import class Text(lpad,trim,rtrim,split,indexOf,concat),\n\tinstance Text String\nimport qualified Text\n\njon :== 'Text'.join\n\nderive gPrint IRCErrors, IRCReplies, Maybe, Either, IRCUser, IRCNumReply\n\nStart = (map (fmap toString) msgs, msgs)\nwhere\n\tmsgs =\n\t\t[ parseIRCMessage \":clooglebot!~cloogle@dhcp-077-249-221-037.chello.nl QUIT\\r\\n\"\n\t\t, parseIRCMessage \":clooglebot!~cloogle QUIT\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 QUIT\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY test\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY :test with spaces\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net NOTICE * :*** Found your hostname\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net QUIT :hoi hoi\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net JOIN #cha,#ch-b #twilight\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net ISON a b c d e f :g h\\r\\n\"\n\t\t, parseIRCMessage \":wilhelm.freenode.net 001 clooglebot :Welcome to the freenode Internet Relay Chat Network clooglebot\\r\\n\"\n\t\t, parseIRCMessage \"PING :orwell.freenode.net\\r\\n\"\n\t\t, parseIRCMessage \":ChanServ!ChanServ@services. MODE #cloogle +o frobnicator\\r\\n\"\n\t\t, parseIRCMessage \":qbot_v01!~qbot@ip-213-124-170-20.ip.prioritytelecom.net PRIVMSG ##chinees :[link] Cloogle - https:\/\/cloogle.org\"\n\t\t]\n\nparseIRCMessage :: String -> Either [Error] IRCMessage\nparseIRCMessage s = case runParser parsePrefix (fromString s) of\n\t\/\/ Prefix is parsed\n\t([(prefix, rest):_], _)\n\t\t\/\/Try parsing a numeric reply\n\t\t= case parse parseReply rest of\n\t\t\t\/\/Try a normal command\n\t\t\tLeft e = case parseCmd rest of\n\t\t\t\tLeft e2 = Left [e2:e]\n\t\t\t\tRight cmd = Right {IRCMessage | irc_prefix=prefix, irc_command=Right cmd}\n\t\t\tRight repl = Right {IRCMessage | irc_prefix=prefix, irc_command=Left repl}\n\t\/\/ Error parsing prefix\n\t(_, es) = Left [\"Error parsing prefix\"]\n\n\/\/Prefix\nparsePrefix :: Parser Char (Maybe (Either IRCUser String))\nparsePrefix\n\t= optional (pToken ':' >>| parseEither parseUser parseHost <* pToken ' ')\nwhere\n\tparseEither :: (Parser a b) (Parser a c) -> Parser a (Either b c)\n\tparseEither p q = Left <$> p <|> Right <$> q\n\n\tparseUser :: Parser Char IRCUser\n\tparseUser = parseNick\n\t\t\t>>= \\nick->optional (pToken '!' >>| parseUsr)\n\t\t\t>>= \\muser->optional (pToken '@' >>| parseHost)\n\t\t\t>>= \\mhost->pure {IRCUser\n\t\t\t\t| irc_nick=nick, irc_user=muser, irc_host=mhost}\n\t\n\tparseUsr :: Parser Char String\n\tparseUsr = toString <$> pSome (pNoneOf [' ', '@':illegal])\n\t\n\tparseNick :: Parser Char String\n\tparseNick = pAlpha \n\t\t>>= \\c ->pMany (pAlpha <|> pDigit <|> pOneOf (fromString \"_-[]\\\\`^{}\"))\n\t\t>>= \\cs->pure (toString [c:cs])\n\n\tparseHost :: Parser Char String\n\tparseHost = jon \".\" <$> (pSepBy parseName (pToken '.'))\n\t\t>>= \\s->optional (pToken '.') >>= pure o maybe s (\\p->s+++toString s)\n\t\twhere\n\t\t\tparseName :: Parser Char String\n\t\t\tparseName = toString <$> pSome (pAlpha <|> pDigit <|> pOneOf ['-', '\/'])\n\n\/\/Parse Cmd\nparseCmd :: [Char] -> Either Error IRCCommand\nparseCmd cs = fst $ gIRCParse{|*|} $ argfun $ split \" \" $ toString cs\n\twhere\n\t\targfun :: [String] -> [String]\n\t\targfun [] = []\n\t\targfun [x:xs]\n\t\t# x = trim x\n\t\t| x.[0] == ':' = [jon \" \" $ [x % (1, size x):map rtrim xs]]\n\t\t| otherwise = [x:argfun xs]\n\n\/\/Reply\nparseReply :: Parser Char IRCNumReply\nparseReply = spaceParser\n\t>>| (pMany (pToken '0') >>| pSome pDigit <* spaceParser)\n\t>>= \\rep->(toString <$> pSome (pNoneOf [' ':illegal]) <* spaceParser)\n\t>>= \\rec->(toString <$> pSome (pNoneOf illegal))\n\t>>= \\msg->pure {IRCNumReply\n\t\t| irc_reply = fromInt $ toInt $ toString rep\n\t\t, irc_recipient = rec\n\t\t, irc_message = msg % (if (msg.[0] == ':') 1 0, size msg)\n\t\t}\n\t<* pToken '\\r' <* pToken '\\n'\n\twhere\n\t\tspaceParser :: Parser Char [Char]\n\t\tspaceParser = pMany $ pToken ' '\n\n\/\/Common parsers\npNoneOf :: [a] -> Parser a a | Eq a\npNoneOf l = pSatisfy (not o flip isMember l)\n\nillegal :: [Char]\nillegal = ['\\x00','\\r','\\n']\n\ninstance toString IRCNumReply where\n\ttoString m = lpad (toString $ toInt m.irc_reply) 3 '0' <+ \" \" <+\n\t\tm.irc_recipient <+ \" \" <+ concat (gIRCPrint{|*|} m.irc_message)\ninstance toString IRCMessage where\n\ttoString m = maybe \"\" (\\s->either ((<+) \":\") id s <+ \" \") m.irc_prefix\n\t\t<+ either toString toString m.irc_command\ninstance toString IRCUser where\n\ttoString m = m.irc_nick <+ maybe \"\" ((<+) \"!\") m.irc_user\n\t\t<+ maybe \"\" ((<+) \"@\") m.irc_host\ninstance toString IRCCommand where\n\ttoString m = jon \" \" (gIRCPrint{|*|} m) +++ \"\\r\\n\"\ninstance toString IRCReplies where toString r = printToString r\ninstance toString IRCErrors where toString r = printToString r\n\n(<+) infixr 5 :: a b -> String | toString a & toString b\n(<+) a b = toString a +++ toString b\n\ninstance fromInt IRCReplies where\n\tfromInt r = case r of \n\t\t1 = RPL_WELCOME\n\t\t2 = RPL_YOURHOST\n\t\t3 = RPL_CREATED\n\t\t4 = RPL_MYINFO\n\t\t5 = RPL_BOUNCE\n\t\t200 = RPL_TRACELINK\n\t\t201 = RPL_TRACECONNECTING\n\t\t202 = RPL_TRACEHANDSHAKE\n\t\t203 = RPL_TRACEUNKNOWN\n\t\t204 = RPL_TRACEOPERATOR\n\t\t205 = RPL_TRACEUSER\n\t\t206 = RPL_TRACESERVER\n\t\t207 = RPL_TRACESERVICE\n\t\t208 = RPL_TRACENEWTYPE\n\t\t209 = RPL_TRACECLASS\n\t\t210 = RPL_TRACERECONNECT\n\t\t211 = RPL_STATSLINKINFO\n\t\t212 = RPL_STATSCOMMANDS\n\t\t219 = RPL_ENDOFSTATS\n\t\t221 = RPL_UMODEIS\n\t\t234 = RPL_SERVLIST\n\t\t235 = RPL_SERVLISTEND\n\t\t242 = RPL_STATSUPTIME\n\t\t243 = RPL_STATSOLINE\n\t\t251 = RPL_LUSERCLIENT\n\t\t252 = RPL_LUSEROP\n\t\t253 = RPL_LUSERUNKNOWN\n\t\t254 = RPL_LUSERCHANNELS\n\t\t255 = RPL_LUSERME\n\t\t256 = RPL_ADMINME\n\t\t257 = RPL_ADMINLOC1\n\t\t258 = RPL_ADMINLOC2\n\t\t259 = RPL_ADMINEMAIL\n\t\t261 = RPL_TRACELOG\n\t\t262 = RPL_TRACEEND\n\t\t263 = RPL_TRYAGAIN\n\t\t301 = RPL_AWAY\n\t\t302 = RPL_USERHOST\n\t\t303 = RPL_ISON\n\t\t304 = RPL_UNAWAY\n\t\t305 = RPL_NOWAWAY\n\t\t311 = RPL_WHOISUSER\n\t\t312 = RPL_WHOISSERVER\n\t\t313 = RPL_WHOISOPERATOR\n\t\t314 = RPL_WHOWASUSER\n\t\t315 = RPL_ENDOFWHO\n\t\t317 = RPL_WHOISIDLE\n\t\t318 = RPL_ENDOFWHOIS\n\t\t319 = RPL_WHOISCHANNELS\n\t\t321 = RPL_LISTSTART\n\t\t322 = RPL_LIST\n\t\t323 = RPL_LISTEND\n\t\t324 = RPL_CHANNELMODEIS\n\t\t325 = RPL_UNIQOPIS\n\t\t331 = RPL_NOTOPIC\n\t\t332 = RPL_TOPIC\n\t\t341 = RPL_INVITING\n\t\t342 = RPL_SUMMONING\n\t\t346 = RPL_INVITELIST\n\t\t347 = RPL_ENDOFINVITELIST\n\t\t348 = RPL_EXCEPTLIST\n\t\t349 = RPL_ENDOFEXCEPTLIST\n\t\t351 = RPL_VERSION\n\t\t352 = RPL_WHOREPLY\n\t\t353 = RPL_NAMREPLY\n\t\t364 = RPL_LINKS\n\t\t365 = RPL_ENDOFLINKS\n\t\t366 = RPL_ENDOFNAMES\n\t\t367 = RPL_BANLIST\n\t\t368 = RPL_ENDOFBANLIST\n\t\t369 = RPL_ENDOFWHOWAS\n\t\t371 = RPL_INFO\n\t\t372 = RPL_MOTD\n\t\t374 = RPL_ENDOFINFO\n\t\t375 = RPL_MOTDSTART\n\t\t376 = RPL_ENDOFMOTD\n\t\t381 = RPL_YOUREOPER\n\t\t382 = RPL_REHASHING\n\t\t383 = RPL_YOURESERVICE\n\t\t391 = RPL_TIME\n\t\t392 = RPL_USERSSTART\n\t\t393 = RPL_USERS\n\t\t394 = RPL_ENDOFUSERS\n\t\t395 = RPL_NOUSERS\n\t\t_ = RPL_UNKNOWN\n\ninstance toInt IRCReplies where\n\ttoInt r = case r of \n\t\tRPL_WELCOME = 1\n\t\tRPL_YOURHOST = 2\n\t\tRPL_CREATED = 3\n\t\tRPL_MYINFO = 4\n\t\tRPL_BOUNCE = 5\n\t\tRPL_TRACELINK = 200\n\t\tRPL_TRACECONNECTING = 201\n\t\tRPL_TRACEHANDSHAKE = 202\n\t\tRPL_TRACEUNKNOWN = 203\n\t\tRPL_TRACEOPERATOR = 204\n\t\tRPL_TRACEUSER = 205\n\t\tRPL_TRACESERVER = 206\n\t\tRPL_TRACESERVICE = 207\n\t\tRPL_TRACENEWTYPE = 208\n\t\tRPL_TRACECLASS = 209\n\t\tRPL_TRACERECONNECT = 210\n\t\tRPL_STATSLINKINFO = 211\n\t\tRPL_STATSCOMMANDS = 212\n\t\tRPL_ENDOFSTATS = 219\n\t\tRPL_UMODEIS = 221\n\t\tRPL_SERVLIST = 234\n\t\tRPL_SERVLISTEND = 234\n\t\tRPL_STATSUPTIME = 242\n\t\tRPL_STATSOLINE = 243\n\t\tRPL_LUSERCLIENT = 251\n\t\tRPL_LUSEROP = 252\n\t\tRPL_LUSERUNKNOWN = 253\n\t\tRPL_LUSERCHANNELS = 254\n\t\tRPL_LUSERME = 255\n\t\tRPL_ADMINME = 256\n\t\tRPL_ADMINLOC1 = 257\n\t\tRPL_ADMINLOC2 = 258\n\t\tRPL_ADMINEMAIL = 259\n\t\tRPL_TRACELOG = 261\n\t\tRPL_TRACEEND = 262\n\t\tRPL_TRYAGAIN = 263\n\t\tRPL_AWAY = 301\n\t\tRPL_USERHOST = 302\n\t\tRPL_ISON = 303\n\t\tRPL_UNAWAY = 304\n\t\tRPL_NOWAWAY = 305\n\t\tRPL_WHOISUSER = 311\n\t\tRPL_WHOISSERVER = 312\n\t\tRPL_WHOISOPERATOR = 313\n\t\tRPL_WHOWASUSER = 314\n\t\tRPL_ENDOFWHO = 315\n\t\tRPL_WHOISIDLE = 317\n\t\tRPL_ENDOFWHOIS = 318\n\t\tRPL_WHOISCHANNELS = 319\n\t\tRPL_LISTSTART = 321\n\t\tRPL_LIST = 322\n\t\tRPL_LISTEND = 323\n\t\tRPL_CHANNELMODEIS = 324\n\t\tRPL_UNIQOPIS = 325\n\t\tRPL_NOTOPIC = 331\n\t\tRPL_TOPIC = 332\n\t\tRPL_INVITING = 341\n\t\tRPL_SUMMONING = 342\n\t\tRPL_INVITELIST = 346\n\t\tRPL_ENDOFINVITELIST = 347\n\t\tRPL_EXCEPTLIST = 348\n\t\tRPL_ENDOFEXCEPTLIST = 349\n\t\tRPL_VERSION = 351\n\t\tRPL_WHOREPLY = 352\n\t\tRPL_NAMREPLY = 353\n\t\tRPL_LINKS = 364\n\t\tRPL_ENDOFLINKS = 365\n\t\tRPL_ENDOFNAMES = 366\n\t\tRPL_BANLIST = 367\n\t\tRPL_ENDOFBANLIST = 367\n\t\tRPL_ENDOFWHOWAS = 369\n\t\tRPL_INFO = 371\n\t\tRPL_MOTD = 372\n\t\tRPL_ENDOFINFO = 374\n\t\tRPL_MOTDSTART = 375\n\t\tRPL_ENDOFMOTD = 376\n\t\tRPL_YOUREOPER = 381\n\t\tRPL_REHASHING = 382\n\t\tRPL_YOURESERVICE = 383\n\t\tRPL_TIME = 391\n\t\tRPL_USERSSTART = 392\n\t\tRPL_USERS = 393\n\t\tRPL_ENDOFUSERS = 394\n\t\tRPL_NOUSERS = 395\n\t\tRPL_UNKNOWN = 998\n\ninstance fromInt IRCErrors where\n\tfromInt r = case r of\n\t\t401 = ERR_NOSUCHNICK\n\t\t402 = ERR_NOSUCHSERVER\n\t\t403 = ERR_NOSUCHCHANNEL\n\t\t404 = ERR_CANNOTSENDTOCHAN\n\t\t405 = ERR_TOOMANYCHANNELS\n\t\t406 = ERR_WASNOSUCHNICK\n\t\t407 = ERR_TOOMANYTARGETS\n\t\t408 = ERR_NOSUCHSERVICE\n\t\t409 = ERR_NOORIGIN\n\t\t411 = ERR_NORECIPIENT\n\t\t412 = ERR_NOTEXTTOSEND\n\t\t413 = ERR_NOTOPLEVEL\n\t\t414 = ERR_WILDTOPLEVEL\n\t\t415 = ERR_BADMASK\n\t\t421 = ERR_UNKNOWNCOMMAND\n\t\t422 = ERR_NOMOTD\n\t\t423 = ERR_NOADMININFO\n\t\t424 = ERR_FILEERROR\n\t\t431 = ERR_NONICKNAMEGIVEN\n\t\t432 = ERR_ERRONEUSNICKNAME\n\t\t433 = ERR_NICKNAMEINUSE\n\t\t436 = ERR_NICKCOLLISION\n\t\t437 = ERR_UNAVAILRESOURCE\n\t\t441 = ERR_USERNOTINCHANNEL\n\t\t442 = ERR_NOTONCHANNEL\n\t\t443 = ERR_USERONCHANNEL\n\t\t444 = ERR_NOLOGIN\n\t\t445 = ERR_SUMMONDISABLED\n\t\t446 = ERR_USERSDISABLED\n\t\t451 = ERR_NOTREGISTERED\n\t\t461 = ERR_NEEDMOREPARAMS\n\t\t462 = ERR_ALREADYREGISTRED\n\t\t463 = ERR_NOPERMFORHOST\n\t\t464 = ERR_PASSWDMISMATCH\n\t\t465 = ERR_YOUREBANNEDCREEP\n\t\t466 = ERR_YOUWILLBEBANNED\n\t\t467 = ERR_KEYSET\n\t\t471 = ERR_CHANNELISFULL\n\t\t472 = ERR_UNKNOWNMODE\n\t\t473 = ERR_INVITEONLYCHAN\n\t\t474 = ERR_BANNEDFROMCHAN\n\t\t475 = ERR_BADCHANNELKEY\n\t\t476 = ERR_BADCHANMASK\n\t\t477 = ERR_NOCHANMODES\n\t\t478 = ERR_BANLISTFULL\n\t\t481 = ERR_NOPRIVILEGES\n\t\t482 = ERR_CHANOPRIVSNEEDED\n\t\t483 = ERR_CANTKILLSERVER\n\t\t484 = ERR_RESTRICTED\n\t\t485 = ERR_UNIQOPPRIVSNEEDED\n\t\t491 = ERR_NOOPERHOST\n\t\t501 = ERR_UMODEUNKNOWNFLAG\n\t\t502 = ERR_USERSDONTMATCH\n\t\t_ = ERR_UNKNOWN\n\ninstance toInt IRCErrors where\n\ttoInt r = case r of\n\t\tERR_NOSUCHNICK = 401\n\t\tERR_NOSUCHSERVER = 402\n\t\tERR_NOSUCHCHANNEL = 403\n\t\tERR_CANNOTSENDTOCHAN = 404\n\t\tERR_TOOMANYCHANNELS = 405\n\t\tERR_WASNOSUCHNICK = 406\n\t\tERR_TOOMANYTARGETS = 407\n\t\tERR_NOSUCHSERVICE = 408\n\t\tERR_NOORIGIN = 409\n\t\tERR_NORECIPIENT = 411\n\t\tERR_NOTEXTTOSEND = 412\n\t\tERR_NOTOPLEVEL = 413\n\t\tERR_WILDTOPLEVEL = 414\n\t\tERR_BADMASK = 415\n\t\tERR_UNKNOWNCOMMAND = 421\n\t\tERR_NOMOTD = 422\n\t\tERR_NOADMININFO = 423\n\t\tERR_FILEERROR = 424\n\t\tERR_NONICKNAMEGIVEN = 431\n\t\tERR_ERRONEUSNICKNAME = 432\n\t\tERR_NICKNAMEINUSE = 433\n\t\tERR_NICKCOLLISION = 436\n\t\tERR_UNAVAILRESOURCE = 437\n\t\tERR_USERNOTINCHANNEL = 441\n\t\tERR_NOTONCHANNEL = 442\n\t\tERR_USERONCHANNEL = 443\n\t\tERR_NOLOGIN = 444\n\t\tERR_SUMMONDISABLED = 445\n\t\tERR_USERSDISABLED = 446\n\t\tERR_NOTREGISTERED = 451\n\t\tERR_NEEDMOREPARAMS = 461\n\t\tERR_ALREADYREGISTRED = 462\n\t\tERR_NOPERMFORHOST = 463\n\t\tERR_PASSWDMISMATCH = 464\n\t\tERR_YOUREBANNEDCREEP = 465\n\t\tERR_YOUWILLBEBANNED = 466\n\t\tERR_KEYSET = 467\n\t\tERR_CHANNELISFULL = 471\n\t\tERR_UNKNOWNMODE = 472\n\t\tERR_INVITEONLYCHAN = 473\n\t\tERR_BANNEDFROMCHAN = 474\n\t\tERR_BADCHANNELKEY = 475\n\t\tERR_BADCHANMASK = 476\n\t\tERR_NOCHANMODES = 477\n\t\tERR_BANLISTFULL = 478\n\t\tERR_NOPRIVILEGES = 481\n\t\tERR_CHANOPRIVSNEEDED = 482\n\t\tERR_CANTKILLSERVER = 483\n\t\tERR_RESTRICTED = 484\n\t\tERR_UNIQOPPRIVSNEEDED = 485\n\t\tERR_NOOPERHOST = 491\n\t\tERR_UMODEUNKNOWNFLAG = 501\n\t\tERR_USERSDONTMATCH = 502\n\t\tERR_UNKNOWN = 999\n","old_contents":"implementation module IRC\n\nimport StdList, StdTuple, StdOverloaded, StdFunc, StdString, StdChar, StdBool\nimport _SystemArray\n\nimport GenPrint\nimport GenIRC\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Either\nimport Data.Maybe\nimport Data.Tuple\nimport Text.Parsers.Simple.Chars\nimport Text.Parsers.Simple.Core\n\nimport StdDebug\n\nfrom Data.Functor import <$>\nfrom Data.Func import $\nfrom StdMisc import undef, abort\nfrom Text import class Text(lpad,trim,rtrim,split,indexOf,concat),\n\tinstance Text String\nimport qualified Text\n\njon :== 'Text'.join\n\nderive gPrint IRCErrors, IRCReplies, Maybe, Either, IRCUser, IRCNumReply\n\nStart = (map (fmap toString) msgs, msgs)\nwhere\n\tmsgs =\n\t\t[ parseIRCMessage \":clooglebot!~cloogle@dhcp-077-249-221-037.chello.nl QUIT\\r\\n\"\n\t\t, parseIRCMessage \":clooglebot!~cloogle QUIT\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 QUIT\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY test\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY :test with spaces\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net NOTICE * :*** Found your hostname\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net QUIT :hoi hoi\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net JOIN #cha,#ch-b #twilight\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net ISON a b c d e f :g h\\r\\n\"\n\t\t, parseIRCMessage \":wilhelm.freenode.net 001 clooglebot :Welcome to the freenode Internet Relay Chat Network clooglebot\\r\\n\"\n\t\t, parseIRCMessage \"PING :orwell.freenode.net\\r\\n\"\n\t\t, parseIRCMessage \":ChanServ!ChanServ@services. MODE #cloogle +o frobnicator\\r\\n\"\n\t\t]\n\nparseIRCMessage :: String -> Either [Error] IRCMessage\nparseIRCMessage s = case runParser parsePrefix (fromString s) of\n\t\/\/ Prefix is parsed\n\t([(prefix, rest):_], _)\n\t\t\/\/Try parsing a numeric reply\n\t\t= case parse parseReply rest of\n\t\t\t\/\/Try a normal command\n\t\t\tLeft e = case parseCmd rest of\n\t\t\t\tLeft e2 = Left [e2:e]\n\t\t\t\tRight cmd = Right {IRCMessage | irc_prefix=prefix, irc_command=Right cmd}\n\t\t\tRight repl = Right {IRCMessage | irc_prefix=prefix, irc_command=Left repl}\n\t\/\/ Error parsing prefix\n\t(_, es) = Left [\"Error parsing prefix\"]\n\n\/\/Prefix\nparsePrefix :: Parser Char (Maybe (Either IRCUser String))\nparsePrefix\n\t= optional (pToken ':' >>| parseEither parseUser parseHost <* pToken ' ')\nwhere\n\tparseEither :: (Parser a b) (Parser a c) -> Parser a (Either b c)\n\tparseEither p q = Left <$> p <|> Right <$> q\n\n\tparseUser :: Parser Char IRCUser\n\tparseUser = parseNick\n\t\t\t>>= \\nick->optional (pToken '!' >>| parseUsr)\n\t\t\t>>= \\muser->optional (pToken '@' >>| parseHost)\n\t\t\t>>= \\mhost->pure {IRCUser\n\t\t\t\t| irc_nick=nick, irc_user=muser, irc_host=mhost}\n\t\n\tparseUsr :: Parser Char String\n\tparseUsr = toString <$> pSome (pNoneOf [' ', '@':illegal])\n\t\n\tparseNick :: Parser Char String\n\tparseNick = pAlpha \n\t\t>>= \\c ->pMany (pAlpha <|> pDigit <|> pOneOf (fromString \"-[]\\\\`^{}\"))\n\t\t>>= \\cs->pure (toString [c:cs])\n\n\tparseHost :: Parser Char String\n\tparseHost = jon \".\" <$> (pSepBy parseName (pToken '.'))\n\t\t>>= \\s->optional (pToken '.') >>= pure o maybe s (\\p->s+++toString s)\n\t\twhere\n\t\t\tparseName :: Parser Char String\n\t\t\tparseName = toString <$> pSome (pAlpha <|> pDigit <|> pOneOf ['-', '\/'])\n\n\/\/Parse Cmd\nparseCmd :: [Char] -> Either Error IRCCommand\nparseCmd cs = fst $ gIRCParse{|*|} $ argfun $ split \" \" $ toString cs\n\twhere\n\t\targfun :: [String] -> [String]\n\t\targfun [] = []\n\t\targfun [x:xs]\n\t\t# x = trim x\n\t\t| x.[0] == ':' = [jon \" \" $ [x % (1, size x):map rtrim xs]]\n\t\t| otherwise = [x:argfun xs]\n\n\/\/Reply\nparseReply :: Parser Char IRCNumReply\nparseReply = spaceParser\n\t>>| (pMany (pToken '0') >>| pSome pDigit <* spaceParser)\n\t>>= \\rep->(toString <$> pSome (pNoneOf [' ':illegal]) <* spaceParser)\n\t>>= \\rec->(toString <$> pSome (pNoneOf illegal))\n\t>>= \\msg->pure {IRCNumReply\n\t\t| irc_reply = fromInt $ toInt $ toString rep\n\t\t, irc_recipient = rec\n\t\t, irc_message = msg % (if (msg.[0] == ':') 1 0, size msg)\n\t\t}\n\t<* pToken '\\r' <* pToken '\\n'\n\twhere\n\t\tspaceParser :: Parser Char [Char]\n\t\tspaceParser = pMany $ pToken ' '\n\n\/\/Common parsers\npNoneOf :: [a] -> Parser a a | Eq a\npNoneOf l = pSatisfy (not o flip isMember l)\n\nillegal :: [Char]\nillegal = ['\\x00','\\r','\\n']\n\ninstance toString IRCNumReply where\n\ttoString m = lpad (toString $ toInt m.irc_reply) 3 '0' <+ \" \" <+\n\t\tm.irc_recipient <+ \" \" <+ concat (gIRCPrint{|*|} m.irc_message)\ninstance toString IRCMessage where\n\ttoString m = maybe \"\" (\\s->either ((<+) \":\") id s <+ \" \") m.irc_prefix\n\t\t<+ either toString toString m.irc_command\ninstance toString IRCUser where\n\ttoString m = m.irc_nick <+ maybe \"\" ((<+) \"!\") m.irc_user\n\t\t<+ maybe \"\" ((<+) \"@\") m.irc_host\ninstance toString IRCCommand where\n\ttoString m = jon \" \" (gIRCPrint{|*|} m) +++ \"\\r\\n\"\ninstance toString IRCReplies where toString r = printToString r\ninstance toString IRCErrors where toString r = printToString r\n\n(<+) infixr 5 :: a b -> String | toString a & toString b\n(<+) a b = toString a +++ toString b\n\ninstance fromInt IRCReplies where\n\tfromInt r = case r of \n\t\t1 = RPL_WELCOME\n\t\t2 = RPL_YOURHOST\n\t\t3 = RPL_CREATED\n\t\t4 = RPL_MYINFO\n\t\t5 = RPL_BOUNCE\n\t\t200 = RPL_TRACELINK\n\t\t201 = RPL_TRACECONNECTING\n\t\t202 = RPL_TRACEHANDSHAKE\n\t\t203 = RPL_TRACEUNKNOWN\n\t\t204 = RPL_TRACEOPERATOR\n\t\t205 = RPL_TRACEUSER\n\t\t206 = RPL_TRACESERVER\n\t\t207 = RPL_TRACESERVICE\n\t\t208 = RPL_TRACENEWTYPE\n\t\t209 = RPL_TRACECLASS\n\t\t210 = RPL_TRACERECONNECT\n\t\t211 = RPL_STATSLINKINFO\n\t\t212 = RPL_STATSCOMMANDS\n\t\t219 = RPL_ENDOFSTATS\n\t\t221 = RPL_UMODEIS\n\t\t234 = RPL_SERVLIST\n\t\t235 = RPL_SERVLISTEND\n\t\t242 = RPL_STATSUPTIME\n\t\t243 = RPL_STATSOLINE\n\t\t251 = RPL_LUSERCLIENT\n\t\t252 = RPL_LUSEROP\n\t\t253 = RPL_LUSERUNKNOWN\n\t\t254 = RPL_LUSERCHANNELS\n\t\t255 = RPL_LUSERME\n\t\t256 = RPL_ADMINME\n\t\t257 = RPL_ADMINLOC1\n\t\t258 = RPL_ADMINLOC2\n\t\t259 = RPL_ADMINEMAIL\n\t\t261 = RPL_TRACELOG\n\t\t262 = RPL_TRACEEND\n\t\t263 = RPL_TRYAGAIN\n\t\t301 = RPL_AWAY\n\t\t302 = RPL_USERHOST\n\t\t303 = RPL_ISON\n\t\t304 = RPL_UNAWAY\n\t\t305 = RPL_NOWAWAY\n\t\t311 = RPL_WHOISUSER\n\t\t312 = RPL_WHOISSERVER\n\t\t313 = RPL_WHOISOPERATOR\n\t\t314 = RPL_WHOWASUSER\n\t\t315 = RPL_ENDOFWHO\n\t\t317 = RPL_WHOISIDLE\n\t\t318 = RPL_ENDOFWHOIS\n\t\t319 = RPL_WHOISCHANNELS\n\t\t321 = RPL_LISTSTART\n\t\t322 = RPL_LIST\n\t\t323 = RPL_LISTEND\n\t\t324 = RPL_CHANNELMODEIS\n\t\t325 = RPL_UNIQOPIS\n\t\t331 = RPL_NOTOPIC\n\t\t332 = RPL_TOPIC\n\t\t341 = RPL_INVITING\n\t\t342 = RPL_SUMMONING\n\t\t346 = RPL_INVITELIST\n\t\t347 = RPL_ENDOFINVITELIST\n\t\t348 = RPL_EXCEPTLIST\n\t\t349 = RPL_ENDOFEXCEPTLIST\n\t\t351 = RPL_VERSION\n\t\t352 = RPL_WHOREPLY\n\t\t353 = RPL_NAMREPLY\n\t\t364 = RPL_LINKS\n\t\t365 = RPL_ENDOFLINKS\n\t\t366 = RPL_ENDOFNAMES\n\t\t367 = RPL_BANLIST\n\t\t368 = RPL_ENDOFBANLIST\n\t\t369 = RPL_ENDOFWHOWAS\n\t\t371 = RPL_INFO\n\t\t372 = RPL_MOTD\n\t\t374 = RPL_ENDOFINFO\n\t\t375 = RPL_MOTDSTART\n\t\t376 = RPL_ENDOFMOTD\n\t\t381 = RPL_YOUREOPER\n\t\t382 = RPL_REHASHING\n\t\t383 = RPL_YOURESERVICE\n\t\t391 = RPL_TIME\n\t\t392 = RPL_USERSSTART\n\t\t393 = RPL_USERS\n\t\t394 = RPL_ENDOFUSERS\n\t\t395 = RPL_NOUSERS\n\t\t_ = RPL_UNKNOWN\n\ninstance toInt IRCReplies where\n\ttoInt r = case r of \n\t\tRPL_WELCOME = 1\n\t\tRPL_YOURHOST = 2\n\t\tRPL_CREATED = 3\n\t\tRPL_MYINFO = 4\n\t\tRPL_BOUNCE = 5\n\t\tRPL_TRACELINK = 200\n\t\tRPL_TRACECONNECTING = 201\n\t\tRPL_TRACEHANDSHAKE = 202\n\t\tRPL_TRACEUNKNOWN = 203\n\t\tRPL_TRACEOPERATOR = 204\n\t\tRPL_TRACEUSER = 205\n\t\tRPL_TRACESERVER = 206\n\t\tRPL_TRACESERVICE = 207\n\t\tRPL_TRACENEWTYPE = 208\n\t\tRPL_TRACECLASS = 209\n\t\tRPL_TRACERECONNECT = 210\n\t\tRPL_STATSLINKINFO = 211\n\t\tRPL_STATSCOMMANDS = 212\n\t\tRPL_ENDOFSTATS = 219\n\t\tRPL_UMODEIS = 221\n\t\tRPL_SERVLIST = 234\n\t\tRPL_SERVLISTEND = 234\n\t\tRPL_STATSUPTIME = 242\n\t\tRPL_STATSOLINE = 243\n\t\tRPL_LUSERCLIENT = 251\n\t\tRPL_LUSEROP = 252\n\t\tRPL_LUSERUNKNOWN = 253\n\t\tRPL_LUSERCHANNELS = 254\n\t\tRPL_LUSERME = 255\n\t\tRPL_ADMINME = 256\n\t\tRPL_ADMINLOC1 = 257\n\t\tRPL_ADMINLOC2 = 258\n\t\tRPL_ADMINEMAIL = 259\n\t\tRPL_TRACELOG = 261\n\t\tRPL_TRACEEND = 262\n\t\tRPL_TRYAGAIN = 263\n\t\tRPL_AWAY = 301\n\t\tRPL_USERHOST = 302\n\t\tRPL_ISON = 303\n\t\tRPL_UNAWAY = 304\n\t\tRPL_NOWAWAY = 305\n\t\tRPL_WHOISUSER = 311\n\t\tRPL_WHOISSERVER = 312\n\t\tRPL_WHOISOPERATOR = 313\n\t\tRPL_WHOWASUSER = 314\n\t\tRPL_ENDOFWHO = 315\n\t\tRPL_WHOISIDLE = 317\n\t\tRPL_ENDOFWHOIS = 318\n\t\tRPL_WHOISCHANNELS = 319\n\t\tRPL_LISTSTART = 321\n\t\tRPL_LIST = 322\n\t\tRPL_LISTEND = 323\n\t\tRPL_CHANNELMODEIS = 324\n\t\tRPL_UNIQOPIS = 325\n\t\tRPL_NOTOPIC = 331\n\t\tRPL_TOPIC = 332\n\t\tRPL_INVITING = 341\n\t\tRPL_SUMMONING = 342\n\t\tRPL_INVITELIST = 346\n\t\tRPL_ENDOFINVITELIST = 347\n\t\tRPL_EXCEPTLIST = 348\n\t\tRPL_ENDOFEXCEPTLIST = 349\n\t\tRPL_VERSION = 351\n\t\tRPL_WHOREPLY = 352\n\t\tRPL_NAMREPLY = 353\n\t\tRPL_LINKS = 364\n\t\tRPL_ENDOFLINKS = 365\n\t\tRPL_ENDOFNAMES = 366\n\t\tRPL_BANLIST = 367\n\t\tRPL_ENDOFBANLIST = 367\n\t\tRPL_ENDOFWHOWAS = 369\n\t\tRPL_INFO = 371\n\t\tRPL_MOTD = 372\n\t\tRPL_ENDOFINFO = 374\n\t\tRPL_MOTDSTART = 375\n\t\tRPL_ENDOFMOTD = 376\n\t\tRPL_YOUREOPER = 381\n\t\tRPL_REHASHING = 382\n\t\tRPL_YOURESERVICE = 383\n\t\tRPL_TIME = 391\n\t\tRPL_USERSSTART = 392\n\t\tRPL_USERS = 393\n\t\tRPL_ENDOFUSERS = 394\n\t\tRPL_NOUSERS = 395\n\t\tRPL_UNKNOWN = 998\n\ninstance fromInt IRCErrors where\n\tfromInt r = case r of\n\t\t401 = ERR_NOSUCHNICK\n\t\t402 = ERR_NOSUCHSERVER\n\t\t403 = ERR_NOSUCHCHANNEL\n\t\t404 = ERR_CANNOTSENDTOCHAN\n\t\t405 = ERR_TOOMANYCHANNELS\n\t\t406 = ERR_WASNOSUCHNICK\n\t\t407 = ERR_TOOMANYTARGETS\n\t\t408 = ERR_NOSUCHSERVICE\n\t\t409 = ERR_NOORIGIN\n\t\t411 = ERR_NORECIPIENT\n\t\t412 = ERR_NOTEXTTOSEND\n\t\t413 = ERR_NOTOPLEVEL\n\t\t414 = ERR_WILDTOPLEVEL\n\t\t415 = ERR_BADMASK\n\t\t421 = ERR_UNKNOWNCOMMAND\n\t\t422 = ERR_NOMOTD\n\t\t423 = ERR_NOADMININFO\n\t\t424 = ERR_FILEERROR\n\t\t431 = ERR_NONICKNAMEGIVEN\n\t\t432 = ERR_ERRONEUSNICKNAME\n\t\t433 = ERR_NICKNAMEINUSE\n\t\t436 = ERR_NICKCOLLISION\n\t\t437 = ERR_UNAVAILRESOURCE\n\t\t441 = ERR_USERNOTINCHANNEL\n\t\t442 = ERR_NOTONCHANNEL\n\t\t443 = ERR_USERONCHANNEL\n\t\t444 = ERR_NOLOGIN\n\t\t445 = ERR_SUMMONDISABLED\n\t\t446 = ERR_USERSDISABLED\n\t\t451 = ERR_NOTREGISTERED\n\t\t461 = ERR_NEEDMOREPARAMS\n\t\t462 = ERR_ALREADYREGISTRED\n\t\t463 = ERR_NOPERMFORHOST\n\t\t464 = ERR_PASSWDMISMATCH\n\t\t465 = ERR_YOUREBANNEDCREEP\n\t\t466 = ERR_YOUWILLBEBANNED\n\t\t467 = ERR_KEYSET\n\t\t471 = ERR_CHANNELISFULL\n\t\t472 = ERR_UNKNOWNMODE\n\t\t473 = ERR_INVITEONLYCHAN\n\t\t474 = ERR_BANNEDFROMCHAN\n\t\t475 = ERR_BADCHANNELKEY\n\t\t476 = ERR_BADCHANMASK\n\t\t477 = ERR_NOCHANMODES\n\t\t478 = ERR_BANLISTFULL\n\t\t481 = ERR_NOPRIVILEGES\n\t\t482 = ERR_CHANOPRIVSNEEDED\n\t\t483 = ERR_CANTKILLSERVER\n\t\t484 = ERR_RESTRICTED\n\t\t485 = ERR_UNIQOPPRIVSNEEDED\n\t\t491 = ERR_NOOPERHOST\n\t\t501 = ERR_UMODEUNKNOWNFLAG\n\t\t502 = ERR_USERSDONTMATCH\n\t\t_ = ERR_UNKNOWN\n\ninstance toInt IRCErrors where\n\ttoInt r = case r of\n\t\tERR_NOSUCHNICK = 401\n\t\tERR_NOSUCHSERVER = 402\n\t\tERR_NOSUCHCHANNEL = 403\n\t\tERR_CANNOTSENDTOCHAN = 404\n\t\tERR_TOOMANYCHANNELS = 405\n\t\tERR_WASNOSUCHNICK = 406\n\t\tERR_TOOMANYTARGETS = 407\n\t\tERR_NOSUCHSERVICE = 408\n\t\tERR_NOORIGIN = 409\n\t\tERR_NORECIPIENT = 411\n\t\tERR_NOTEXTTOSEND = 412\n\t\tERR_NOTOPLEVEL = 413\n\t\tERR_WILDTOPLEVEL = 414\n\t\tERR_BADMASK = 415\n\t\tERR_UNKNOWNCOMMAND = 421\n\t\tERR_NOMOTD = 422\n\t\tERR_NOADMININFO = 423\n\t\tERR_FILEERROR = 424\n\t\tERR_NONICKNAMEGIVEN = 431\n\t\tERR_ERRONEUSNICKNAME = 432\n\t\tERR_NICKNAMEINUSE = 433\n\t\tERR_NICKCOLLISION = 436\n\t\tERR_UNAVAILRESOURCE = 437\n\t\tERR_USERNOTINCHANNEL = 441\n\t\tERR_NOTONCHANNEL = 442\n\t\tERR_USERONCHANNEL = 443\n\t\tERR_NOLOGIN = 444\n\t\tERR_SUMMONDISABLED = 445\n\t\tERR_USERSDISABLED = 446\n\t\tERR_NOTREGISTERED = 451\n\t\tERR_NEEDMOREPARAMS = 461\n\t\tERR_ALREADYREGISTRED = 462\n\t\tERR_NOPERMFORHOST = 463\n\t\tERR_PASSWDMISMATCH = 464\n\t\tERR_YOUREBANNEDCREEP = 465\n\t\tERR_YOUWILLBEBANNED = 466\n\t\tERR_KEYSET = 467\n\t\tERR_CHANNELISFULL = 471\n\t\tERR_UNKNOWNMODE = 472\n\t\tERR_INVITEONLYCHAN = 473\n\t\tERR_BANNEDFROMCHAN = 474\n\t\tERR_BADCHANNELKEY = 475\n\t\tERR_BADCHANMASK = 476\n\t\tERR_NOCHANMODES = 477\n\t\tERR_BANLISTFULL = 478\n\t\tERR_NOPRIVILEGES = 481\n\t\tERR_CHANOPRIVSNEEDED = 482\n\t\tERR_CANTKILLSERVER = 483\n\t\tERR_RESTRICTED = 484\n\t\tERR_UNIQOPPRIVSNEEDED = 485\n\t\tERR_NOOPERHOST = 491\n\t\tERR_UMODEUNKNOWNFLAG = 501\n\t\tERR_USERSDONTMATCH = 502\n\t\tERR_UNKNOWN = 999\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"bdbd303f7cddbaebc68ee3d72436834d381b45c2","subject":"Remove haskell code from builddb","message":"Remove haskell code from builddb\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org","old_file":"backend\/builddb.icl","new_file":"backend\/builddb.icl","new_contents":"module builddb\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import const, o\nimport StdList\nimport StdMisc\nimport StdString\nimport StdTuple\n\nimport Data.Either\nfrom Data.Func import $, mapSt\nimport Data.Functor\nimport Data.Maybe\nimport System.CommandLine\nfrom Text import class Text(concat,startsWith), instance Text String\n\nimport TypeDB\nimport Type\nfrom TypeDBFactory import :: DclCache, findModules, getModuleTypes,\n\tconstructor_functions, record_functions\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const False)\n\t , (\"CleanInotify\", const False)\n\t , (\"CleanPrettyPrint\", const False)\n\t , (\"CleanSerial\", const False)\n\t , (\"CleanTypeUnifier\", const False)\n\t , (\"Cloogle\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"GraphCopy\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"Platform\", const False)\n\t , (\"Sapl\", const False)\n\t , (\"SoccerFun\", const False)\n\t , (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"iTasks\", const False)\n\t , (\"libcloogle\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"Platform\/Deprecated\"\n\t , \"Platform\/Data\/Graph\/Inductive\/Query\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (db, w) = loop cli.root mods newDb w\n\t# db = putFunctions predefFunctions db\n\t# db = putClasses predefClasses db\n\t# db = putTypes predefTypes db\n\t# db = putFunctions (flatten $ map constructor_functions predefTypes) db\n\t# db = putFunctions (flatten $ map record_functions predefTypes) db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] TypeDB *World -> *(TypeDB, *World)\n\tloop _ [] db w = (db,w)\n\tloop root [(lib,mod,iscore):list] db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t# (db, w) = getModuleTypes root mod lib iscore db w\n\t= loop root list db w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ moduleCount db\n\t\t\t\t, functionCount db\n\t\t\t\t, macroCount db\n\t\t\t\t, typeCount db\n\t\t\t\t, classCount db\n\t\t\t\t, instanceCount db\n\t\t\t\t, deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [(Location, ExtendedType)]\npredefFunctions\n\t= [ ( Builtin \"if\"\n\t , ET (Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []) zero\n\t )\n\t , ( Builtin \"dynamic\"\n\t , ET (Func [Var \"a\"] (Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [(Location, [TypeVar], ClassContext, [(Name, ExtendedType)])]\npredefClasses\n\t= [ ( Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [(Location, ExtendedTypeDef)]\npredefTypes\n\t= [ ( Builtin \"Bool\"\n\t , { deft\n\t & etd_typedef.td_name = \"Bool\"\n\t , etd_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\", { deft & etd_typedef.td_name = \"Int\" } )\n\t , ( Builtin \"Real\", { deft & etd_typedef.td_name = \"Real\" } )\n\t , ( Builtin \"Char\", { deft & etd_typedef.td_name = \"Char\" } )\n\t , ( Builtin \"String\", { deft & etd_typedef.td_name = \"String\",\n\t etd_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\", { deft & etd_typedef.td_name = \"Dynamic\" } )\n\t , ( Builtin \"File\", { deft & etd_typedef.td_name = \"File\" } )\n\t , ( Builtin \"World\", { deft & etd_typedef.td_name = \"World\",\n\t etd_typedef.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {etd_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract}, etd_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n","old_contents":"module builddb\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import const, o\nimport StdList\nimport StdMisc\nimport StdString\nimport StdTuple\n\nimport Data.Either\nfrom Data.Func import $, mapSt\nimport Data.Functor\nimport Data.Maybe\nimport System.CommandLine\nfrom Text import class Text(concat,startsWith), instance Text String\n\nimport TypeDB\nimport Type\nfrom TypeDBFactory import :: DclCache, findModules, getModuleTypes,\n\tconstructor_functions, record_functions\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const False)\n\t , (\"CleanInotify\", const False)\n\t , (\"CleanPrettyPrint\", const False)\n\t , (\"CleanSerial\", const False)\n\t , (\"CleanTypeUnifier\", const False)\n\t , (\"Cloogle\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"GraphCopy\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"Platform\", const False)\n\t , (\"Sapl\", const False)\n\t , (\"SoccerFun\", const False)\n\t , (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"iTasks\", const False)\n\t , (\"libcloogle\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"Platform\/Deprecated\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (db, w) = loop cli.root mods newDb w\n\t# db = putFunctions predefFunctions db\n\t# db = putClasses predefClasses db\n\t# db = putTypes predefTypes db\n\t# db = putFunctions (flatten $ map constructor_functions predefTypes) db\n\t# db = putFunctions (flatten $ map record_functions predefTypes) db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] TypeDB *World -> *(TypeDB, *World)\n\tloop _ [] db w = (db,w)\n\tloop root [(lib,mod,iscore):list] db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t# (db, w) = getModuleTypes root mod lib iscore db w\n\t= loop root list db w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ moduleCount db\n\t\t\t\t, functionCount db\n\t\t\t\t, macroCount db\n\t\t\t\t, typeCount db\n\t\t\t\t, classCount db\n\t\t\t\t, instanceCount db\n\t\t\t\t, deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [(Location, ExtendedType)]\npredefFunctions\n\t= [ ( Builtin \"if\"\n\t , ET (Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []) zero\n\t )\n\t , ( Builtin \"dynamic\"\n\t , ET (Func [Var \"a\"] (Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [(Location, [TypeVar], ClassContext, [(Name, ExtendedType)])]\npredefClasses\n\t= [ ( Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [(Location, ExtendedTypeDef)]\npredefTypes\n\t= [ ( Builtin \"Bool\"\n\t , { deft\n\t & etd_typedef.td_name = \"Bool\"\n\t , etd_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\", { deft & etd_typedef.td_name = \"Int\" } )\n\t , ( Builtin \"Real\", { deft & etd_typedef.td_name = \"Real\" } )\n\t , ( Builtin \"Char\", { deft & etd_typedef.td_name = \"Char\" } )\n\t , ( Builtin \"String\", { deft & etd_typedef.td_name = \"String\",\n\t etd_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\", { deft & etd_typedef.td_name = \"Dynamic\" } )\n\t , ( Builtin \"File\", { deft & etd_typedef.td_name = \"File\" } )\n\t , ( Builtin \"World\", { deft & etd_typedef.td_name = \"World\",\n\t etd_typedef.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {etd_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract}, etd_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"9099afbc8b40a7113fa79744fcffdf93e4a348a3","subject":"Copy editing #201 (resolves #203)","message":"Copy editing #201 (resolves #203)\n","repos":"clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_basicvalues\n\t, bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_basicvalues =\n\t{ syntax_title = \"basicvalues\"\n\t, syntax_patterns = map exact [\"'.'\", \"[+-]?\\\\d+\", \"[+-]?0[0-7]+\", \"[-+]?0x[0-9a-fA-F]+\", \"'.'\", \"True\", \"False\", \"E\"]\n\t, syntax_code = [\"0x...\", \"0...\", \"True\", \"False\", \"'...'\", \"...E...\"]\n\t, syntax_description =\n\t\t\"Constant basic values can be of type Int, Char, Real and Bool.\\n\\n\" +\n\t\t\"Integers can be either defined in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix).\\n\\n\" +\n\t\t\"Characters can either be printable characters (except `'`) or an escape sequence.\\n\\n\" +\n\t\t\"Reals can be suffixed by a power of ten in the scientific notation.\\n\\n\" +\n\t\t\"Boolean values by their only inhabitants {{True}} and {{False}}.\\n\\n\" +\n\t\t\"Basic values can also be pattern matched with these notations.\"\n\t, syntax_doc_locations = [CLR 4 \"1.1\" \"_Toc311798017\"]\n\t, syntax_examples = map EX\n\t\t[ \"(42, -42, +42) \/\/ Tuple with 42, -42 and 42 in decimal\"\n\t\t, \"(052, -052, +052) \/\/ Tuple with 42, -42 and 42 in octal\"\n\t\t, \"(0x2a, -0x2a, +0x2A) \/\/ Tuple with 42, -42 and 42 in hexadecimal\"\n\t\t, \"('a', '\\\\x2a', '\\\\052') \/\/ Tuple with a normal character, a literal quote and twice the character with ordinal 42\"\n\t\t, \"['\\\\n', '\\\\r', '\\\\f', '\\\\b', '\\\\t', '\\\\', '\\'']\\n\" +\n\t\t \" \/\/All character escapes\"\n\t\t, \"(True, False) \/\/ All booleans in a tuple\"\n\t\t, \"(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\\n\" +\n\t\t \" \/\/Several reals\"\n\t\t]\n\t}\n\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... [| ...] :: ... \", \"derive ... ... [of ...] [with ...]\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples = map EX\n\t\t[ \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, \"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context. The context will become an argument.\\n\" +\n\t\t \"derive gFun CONS of {gcd_arity} with f _ \/\/ A derivation that does not use all arguments. The ompiler can optimize even more\\n\" +\n\t\t \"gFun{|CONS of {gcd_arity}|} f _ = \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t, \"abc ['abc':rest] = True \/\/ The special syntax can als be used to patternmatch\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_basicvalues\n\t, bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_basicvalues =\n\t{ syntax_title = \"basicvalues\"\n\t, syntax_patterns = map exact [\"'.'\", \"[+-]?\\\\d+\", \"[+-]?0[0-7]+\", \"[-+]?0x[0-9a-fA-F]+\", \"'.'\", \"True\", \"False\", \"E\"]\n\t, syntax_code = [\"0x...\", \"0...\", \"True\", \"False\", \"'...'\", \"...E...\"]\n\t, syntax_description =\n\t\t\"Constant basic values can be of type Int, Char, Real and Bool.\\n\\n\" +\n\t\t\"Integers can be either defined in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix).\\n\\n\" +\n\t\t\"Characters can either be printable characters (except `'`) or an escape sequence.\\n\\n\" +\n\t\t\"Reals can be suffixed by a power of ten in the scientific notation.\\n\\n\" +\n\t\t\"Boolean values by their only inhabitants {{True}} and {{False}}.\\n\\n\" +\n\t\t\"Basic values can also be pattern matched with these notations.\"\n\t, syntax_doc_locations = [CLR 4 \"1.1\" \"_Toc311798017\"]\n\t, syntax_examples = map EX\n\t\t[ \"(42, -42, +42) \/\/ Tuple with 42, -42 and 42 in decimal\"\n\t\t, \"(052, -052, +052) \/\/ Tuple with 42, -42 and 42 in octal\"\n\t\t, \"(0x2a, -0x2a, +0x2A) \/\/ Tuple with 42, -42 and 42 in hexadecimal\"\n\t\t, \"('a', '\\\\x2a', '\\\\052') \/\/ Tuple with a normal character, a literal quote and twice the character with ordinal 42\"\n\t\t, \"['\\\\n', '\\\\r', '\\\\f', '\\\\b', '\\\\t', '\\\\', '\\'']\\n\" +\n\t\t \" \/\/All character escapes\"\n\t\t, \"(True, False) \/\/ All booleans in a tuple\"\n\t\t, \"(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\\n\" +\n\t\t \" \/\/Several reals\"\n\t\t]\n\t}\n\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... [| ...] :: ... \", \"derive ... ... [of ...] [with ...]\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, EX \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, EXs \"macro\" $\n\t\t\t\"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context. The context will become an argument.\\n\" +\n\t\t\t\"derive gFun CONS of {gcd_arity} with f _ \/\/ A derivation that does not use all arguments. The ompiler can optimize even more\\n\" +\n\t\t\t\"gFun{|CONS of {gcd_arity}|} f _ = \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t, \"abc ['abc':rest] = True \/\/ The special syntax can als be used to patternmatch\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"ead65972e85682e2e2306178e39eb0e92d63d877","subject":"clean pidigits","message":"clean pidigits\n","repos":"kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout","old_file":"bench\/pidigits\/pidigits.icl","new_file":"bench\/pidigits\/pidigits.icl","new_contents":"\/* The Great Win32 Computer Language Shootout \n http:\/\/shootout.alioth.debian.org\/\n\n contributed by Isaac Gouy (Clean novice)\n*\/\n\n\nmodule pidigits\nimport StdEnv,ArgEnv,BigInt,Rational\n\nStart = format 1 1 (stream argi [] unit ts) \"\" \n \nstream n digits z [x:xs] \n | n > 0 \n | isSafe z y \n = stream (n-1) (digits ++ [toChar(y + 48)])(produce z y) [x:xs]\n = stream n digits (consume z x) xs\n = digits\n where y = next z \n\nts = [T (toBigInt k) (toBigInt(4*k+2)) zero (toBigInt(2*k+1)) \\\\ k <- [1..]]\nnext z = entier (toReal (extract z three))\nisSafe z n = (n == entier (toReal (extract z four)) )\nproduce z n = compose (T ten (toBigInt (-10*n)) zero one) z\nconsume z z` = compose z z` \n\n:: Transform = T BigInt BigInt BigInt BigInt\nextract (T q r s t) x = (q * x + r) \/: (s * x + t)\nunit = T one zero zero one\ncompose (T q r s t) (T q` r` s` t`) \n\t= (T (q*q` + r*s`)(q*r` + r*t`)(s*q` + t*s`)(s*r` + t*t`))\t\n\n\/\/ BigInt constants\nthree = toBigInt 3\nfour = toBigInt 4\nten = toBigInt 10\t\n\n\nformat :: !Int !Int !.[Char] !{#Char} -> {#Char}\nformat n i [] s \n | n == 1 = s\n | n < 10 = format (n+1) i [] (s +++ \" \")\n = (s +++ \"\\t :\" +++ toString (i-1) +++ \"\\n\")\nformat n i [c:digits] s\n | n < 10 = format (n+1)(i+1) digits s`\n = format 1 (i+1) digits (s` +++ \"\\t :\" +++ toString i +++ \"\\n\")\n where s` = s +++ toString c\n\n\t\nargi = if (argAsInt <= 0) 1 argAsInt\n where\n argv = getCommandLine\n argAsInt = if (size argv == 2)(toInt argv.[1]) 1\t\n\n\n ","old_contents":"","returncode":1,"stderr":"error: pathspec 'bench\/pidigits\/pidigits.icl' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Clean"} {"commit":"e3ef80856c46ebc404e79b0f5039e44b7ff77e47","subject":"Document syntax (#180): qualified identifiers; record disambiguation","message":"Document syntax (#180): qualified identifiers; record disambiguation\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"9e17c31bf636c13e34a66517373418d9dc26441c","subject":"Better version that does not print new lines","message":"Better version that does not print new lines\n\ngit-svn-id: a20303ca0449e3ef575223833049c5e6a53b9062@646914 13f79535-47bb-0310-9956-ffa450edef68\n","repos":"apache\/commons-exec,mohanaraosv\/commons-exec,mohanaraosv\/commons-exec,sgoeschl\/commons-exec,sgoeschl\/commons-exec,apache\/commons-exec","old_file":"src\/test\/scripts\/forever.dcl","new_file":"src\/test\/scripts\/forever.dcl","new_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r$!\r$! Licensed to the Apache Software Foundation (ASF) under one or more\r$! contributor license agreements. See the NOTICE file distributed with\r$! this work for additional information regarding copyright ownership.\r$! The ASF licenses this file to You under the Apache License, Version 2.0\r$! (the \"License\"); you may not use this file except in compliance with\r$! the License. You may obtain a copy of the License at\r$!\r$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\r$!\r$! Unless required by applicable law or agreed to in writing, software\r$! distributed under the License is distributed on an \"AS IS\" BASIS,\r$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r$! See the License for the specific language governing permissions and\r$! limitations under the License.\r$! \r$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r$!\r$! run an infinite loop so the script will never ever terminate\r$!\r$! Suppress timeout warning\r$ SET MESSAGE \/NOFACILITY \/NOIDENTIFICATION \/NOSEVERITY \/NOTEXT\r$!\r$LOOP:\r$ read \/prompt=\".\"\/time_out=1 sys$command dummy\r$ GOTO LOOP","old_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r$!\r$! Licensed to the Apache Software Foundation (ASF) under one or more\r$! contributor license agreements. See the NOTICE file distributed with\r$! this work for additional information regarding copyright ownership.\r$! The ASF licenses this file to You under the Apache License, Version 2.0\r$! (the \"License\"); you may not use this file except in compliance with\r$! the License. You may obtain a copy of the License at\r$!\r$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\r$!\r$! Unless required by applicable law or agreed to in writing, software\r$! distributed under the License is distributed on an \"AS IS\" BASIS,\r$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r$! See the License for the specific language governing permissions and\r$! limitations under the License.\r$! \r$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r$!\r$! run an infinite loop so the script will never ever terminate\r$!\r$LOOP:\r$ WAIT 00:00:01\r$ WRITE SYS$OUTPUT \".\" ! this includes a new line ;-)\r$ GOTO LOOP","returncode":0,"stderr":"","license":"apache-2.0","lang":"Clean"} {"commit":"105d010797e0aa93622b2f42086a94e56c76aa1f","subject":"Add generic dependency to syntax.icl","message":"Add generic dependency to syntax.icl","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\"\n\t\t, \"A generic function can only contain a generic context written with a different syntax.\"\n\t\t, \"The generic dependency is written without the kind specification and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a\" \/\/ Generic dependency\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"117c4d1b394fe3622c58406aa7aa6be9913ab5e2","subject":"Fix bug with library-module name clashes","message":"Fix bug with library-module name clashes\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/builddb.icl","new_file":"backend\/builddb.icl","new_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, ::Macro{..}, ::ModuleInfo{..},\n\tinstance zero TypeExtras, instance zero ModuleInfo\n\n\/\/ StdEnv\nfrom StdFunc import const, flip, o\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf,startsWith),\n\tinstance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String,\n\tinstance print Type, instance print Priority, instance == Type\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Instances,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos,td_ident},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const False)\n\t , (\"CleanInotify\", const False)\n\t , (\"CleanPrettyPrint\", const False)\n\t , (\"CleanSerial\", const False)\n\t , (\"CleanTypeUnifier\", const False)\n\t , (\"Cloogle\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"GraphCopy\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"Platform\", const False)\n\t , (\"Sapl\", const False)\n\t , (\"SoccerFun\", const False)\n\t , (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"iTasks\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"Platform\/Deprecated\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putClasses predefClasses db\n\t# db = 'DB'.putTypes predefTypes db\n\t# db = 'DB'.putFunctions (flatten $ map constructor_functions predefTypes) db\n\t# db = 'DB'.putFunctions (flatten $ map record_functions predefTypes) db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = 'DB'.saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] 'DB'.TypeDB\n\t\t*DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod,iscore):list] db cache w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t# (db, cache, w) = getModuleTypes root mod lib iscore cache db w\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !'DB'.TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ 'DB'.moduleCount db\n\t\t\t\t, 'DB'.functionCount db\n\t\t\t\t, 'DB'.macroCount db\n\t\t\t\t, 'DB'.typeCount db\n\t\t\t\t, 'DB'.classCount db\n\t\t\t\t, 'DB'.instanceCount db\n\t\t\t\t, 'DB'.deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t , ( 'DB'.Builtin \"dynamic\"\n\t , 'DB'.ET ('T'.Func ['T'.Var \"a\"] ('T'.Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext, [('DB'.Name, 'DB'.ExtendedType)])]\npredefClasses\n\t= [ ( 'DB'.Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"_#Array\" ['T'.Type \"Char\" []]) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[], 'Type'.cons_priority=Nothing}\n\n\/\/ Exclude Root Library Check for core Base module\nfindModules :: ![String] !String !'DB'.Library ('DB'.Module -> Bool) !String !*World\n\t-> *(![('DB'.Library, 'DB'.Module, Bool)], !*World)\nfindModules ex root lib iscore base w\n| any ((<>) -1 o flip indexOf path) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! (Ok fps) = fps\n#! mods = map (\\s -> let mod = basedot +++ s % (0, size s - 5) in\n\t(lib, mod, iscore mod)) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (findModules ex root lib iscore o ((+++) basedot)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any ((<>) -1 o flip indexOf (path +++ \"\/\" +++ s)) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: (String -> Bool)\n\tisDirectory = not o isMember '.' o fromString\n\ngetModuleTypes :: String 'DB'.Module 'DB'.Library Bool\n\t*DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib iscore cache db w\n#! w = snd (fclose (stderr <<< lib <<< \":\" <<< mod <<< \"\\n\") w)\n# (Right dcl,cache,w) = readModule False cache w\n# (icl,cache,w) = readModule True cache w\n# icl = case icl of (Left _) = Nothing; (Right x) = Just x\n# modname = dcl.mod_ident.id_name\n# lib = lib % (0, size lib - size modname + size mod - 1)\n# db = 'DB'.putFunctions (pd_typespecs lib modname dcl.mod_defs icl) db\n# db = 'DB'.putInstances (pd_instances lib modname dcl.mod_defs icl) db\n# db = 'DB'.putClasses (pd_classes lib modname dcl.mod_defs icl) db\n# typedefs = pd_types lib modname dcl.mod_defs icl\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib modname dcl.mod_defs icl) db\n# db = 'DB'.putDerivationss (pd_derivations lib modname dcl.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib modname dcl.mod_defs) db\n# db = 'DB'.putModule lib modname {zero & is_core=iscore} db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine pos) Nothing id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= 'T'.toMaybePriority}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- dcl]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id dcl of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id dcl\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):dcl]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:dcl] = findTypeSpec id dcl\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, String, 'DB'.Location)])]\n\tpd_derivations lib mod dcl\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, cpp gc_type, 'DB'.Location lib mod (toLine gc_pos) Nothing \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- dcl, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType gen_type)\n\t\t {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars\n\t\t , te_representation=Just $ cpp gen}\n\t\t ) \\\\ gen=:(PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars}) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [g.gen_pos \\\\ PD_Generic g <- pms | g.gen_ident.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_typespecs :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType t)\n\t\t { zero & te_priority = 'T'.toMaybePriority p\n\t\t , te_representation = Just $ cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pos \\\\ PD_TypeSpec pos id _ _ _ <- pms | id.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_instances :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Class, [('DB'.Type, String)], 'DB'.Location)]\n\tpd_instances lib mod dcl icl\n\t\t= [( id\n\t\t , types\n\t\t , 'DB'.Location lib mod (toLine pos) (findIclLine id (map fst types) =<< icl) \"\"\n\t\t ) \\\\ (id,types,pos) <- instances]\n\twhere\n\t\tinstances = map (appSnd3 (map (\\t -> ('T'.toType t, cpp t)))) $\n\t\t\t[(i.pi_ident.id_name, i.pi_types, i.pi_pos) \\\\ PD_Instance {pim_pi=i} <- dcl]\n\t\t\t++ [(i.pi_ident.id_name, i.pi_types, i.pi_pos) \\\\ PD_Instances pis <- dcl, {pim_pi=i} <- pis]\n\n\t\tfindIclLine :: String ['T'.Type] ParsedModule -> Maybe Int\n\t\tfindIclLine name types {mod_defs=pms}\n\t\t\t= case [pi_pos\n\t\t\t\t\t\\\\ PD_Instance {pim_pi={pi_pos,pi_ident,pi_types}} <- pms\n\t\t\t\t\t| (pi_ident.id_name == name && map 'T'.toType pi_types == types)] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_classes :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod dcl icl\n\t# dcl = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) dcl\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} dcl)\n\t\t-> let\n\t\t\ttypespecs = pd_typespecs lib mod dcl icl\n\t\t\tmacros = pd_macros lib mod dcl\n\t\t\tgetMacro n = case filter ((==) n o 'DB'.getName o fst) macros of\n\t\t\t\t[] = Nothing\n\t\t\t\t[(_,m):_] = Just m.macro_as_string\n\t\t\tupdateRepresentation n ('DB'.ET t te)\n\t\t\t\t= 'DB'.ET t {te & te_representation = getMacro n <|> te.te_representation}\n\t\tin ('DB'.Location lib mod (toLine class_pos) (findIclLine id_name =<< icl) id_name\n\t\t , map 'T'.toTypeVar class_args\n\t\t , flatten $ map 'T'.toClassContext class_context\n\t\t , [(f,updateRepresentation f et) \\\\ ('DB'.Location _ _ _ _ f, et) <- typespecs])) dcl\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [class_pos \\\\ PD_Class {class_ident,class_pos} _ <- pms | class_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_types :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod dcl icl\n\t\t= [let name = 'T'.td_name td in\n\t\t\t('DB'.Location lib mod (toLine ptd.td_pos) (findIclLine name =<< icl) name, td)\n\t\t \\\\ PD_Type ptd <- dcl, td <- ['T'.toTypeDef ptd]]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [td_pos \\\\ PD_Type {td_ident,td_pos} <- pms | td_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\n\treadModule :: Bool *DclCache *World -> *(Either String ParsedModule, *DclCache, *World)\n\treadModule icl cache w\n\t# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ if icl \".icl\" \".dcl\"\n\t# (ok,f,w) = fopen filename FReadText w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n\t cache = {cache & hash_table=ht}\n\t# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" icl mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n\t cache = {cache & hash_table=ht}\n\t# (ok,w) = fclose f w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t= (Right pm, cache, w)\n\nconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nconstructor_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\nconstructor_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\n\nprint_prio :: (Maybe 'T'.Priority) -> [String]\nprint_prio Nothing = []\nprint_prio (Just p) = [\" \"] ++ print False p\n\nrecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nrecord_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\nrecord_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","old_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, ::Macro{..}, ::ModuleInfo{..},\n\tinstance zero TypeExtras, instance zero ModuleInfo\n\n\/\/ StdEnv\nfrom StdFunc import const, flip, o\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf,startsWith),\n\tinstance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String,\n\tinstance print Type, instance print Priority, instance == Type\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Instances,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos,td_ident},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const False)\n\t , (\"CleanInotify\", const False)\n\t , (\"CleanPrettyPrint\", const False)\n\t , (\"CleanSerial\", const False)\n\t , (\"CleanTypeUnifier\", const False)\n\t , (\"Cloogle\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"GraphCopy\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"Platform\", const False)\n\t , (\"Sapl\", const False)\n\t , (\"SoccerFun\", const False)\n\t , (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"iTasks\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"Platform\/Deprecated\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putClasses predefClasses db\n\t# db = 'DB'.putTypes predefTypes db\n\t# db = 'DB'.putFunctions (flatten $ map constructor_functions predefTypes) db\n\t# db = 'DB'.putFunctions (flatten $ map record_functions predefTypes) db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = 'DB'.saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] 'DB'.TypeDB\n\t\t*DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod,iscore):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib iscore cache db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !'DB'.TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ 'DB'.moduleCount db\n\t\t\t\t, 'DB'.functionCount db\n\t\t\t\t, 'DB'.macroCount db\n\t\t\t\t, 'DB'.typeCount db\n\t\t\t\t, 'DB'.classCount db\n\t\t\t\t, 'DB'.instanceCount db\n\t\t\t\t, 'DB'.deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t , ( 'DB'.Builtin \"dynamic\"\n\t , 'DB'.ET ('T'.Func ['T'.Var \"a\"] ('T'.Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext, [('DB'.Name, 'DB'.ExtendedType)])]\npredefClasses\n\t= [ ( 'DB'.Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"_#Array\" ['T'.Type \"Char\" []]) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[], 'Type'.cons_priority=Nothing}\n\n\/\/ Exclude Root Library Check for core Base module\nfindModules :: ![String] !String !'DB'.Library ('DB'.Module -> Bool) !String !*World\n\t-> *(![('DB'.Library, 'DB'.Module, Bool)], !*World)\nfindModules ex root lib iscore base w\n| any (\\e -> indexOf e path <> -1) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s -> let mod = basedot +++ s % (0, size s - 5) in\n\t(lib, mod, iscore mod)) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (\\d -> findModules ex root lib iscore (basedot +++ d)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any (\\e -> indexOf e (path +++ \"\/\" +++ s) <> -1) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String 'DB'.Module 'DB'.Library Bool\n\t*DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib iscore cache db w\n# (Right dcl,cache,w) = readModule False cache w\n# (icl,cache,w) = readModule True cache w\n# icl = case icl of (Left _) = Nothing; (Right x) = Just x\n# mod = dcl.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putFunctions (pd_typespecs lib mod dcl.mod_defs icl) db\n# db = 'DB'.putInstances (pd_instances lib mod dcl.mod_defs icl) db\n# db = 'DB'.putClasses (pd_classes lib mod dcl.mod_defs icl) db\n# typedefs = pd_types lib mod dcl.mod_defs icl\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib mod dcl.mod_defs icl) db\n# db = 'DB'.putDerivationss (pd_derivations lib mod dcl.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib mod dcl.mod_defs) db\n# db = 'DB'.putModule lib mod {zero & is_core=iscore} db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine pos) Nothing id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= 'T'.toMaybePriority}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- dcl]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id dcl of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id dcl\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):dcl]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:dcl] = findTypeSpec id dcl\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, String, 'DB'.Location)])]\n\tpd_derivations lib mod dcl\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, cpp gc_type, 'DB'.Location lib mod (toLine gc_pos) Nothing \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- dcl, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType gen_type)\n\t\t {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars\n\t\t , te_representation=Just $ cpp gen}\n\t\t ) \\\\ gen=:(PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars}) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [g.gen_pos \\\\ PD_Generic g <- pms | g.gen_ident.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_typespecs :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType t)\n\t\t { zero & te_priority = 'T'.toMaybePriority p\n\t\t , te_representation = Just $ cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pos \\\\ PD_TypeSpec pos id _ _ _ <- pms | id.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_instances :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Class, [('DB'.Type, String)], 'DB'.Location)]\n\tpd_instances lib mod dcl icl\n\t\t= [( id\n\t\t , types\n\t\t , 'DB'.Location lib mod (toLine pos) (findIclLine id (map fst types) =<< icl) \"\"\n\t\t ) \\\\ (id,types,pos) <- instances]\n\twhere\n\t\tinstances = map (appSnd3 (map (\\t -> ('T'.toType t, cpp t)))) $\n\t\t\t[(i.pi_ident.id_name, i.pi_types, i.pi_pos) \\\\ PD_Instance {pim_pi=i} <- dcl]\n\t\t\t++ [(i.pi_ident.id_name, i.pi_types, i.pi_pos) \\\\ PD_Instances pis <- dcl, {pim_pi=i} <- pis]\n\n\t\tfindIclLine :: String ['T'.Type] ParsedModule -> Maybe Int\n\t\tfindIclLine name types {mod_defs=pms}\n\t\t\t= case [pi_pos\n\t\t\t\t\t\\\\ PD_Instance {pim_pi={pi_pos,pi_ident,pi_types}} <- pms\n\t\t\t\t\t| (pi_ident.id_name == name && map 'T'.toType pi_types == types)] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_classes :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod dcl icl\n\t# dcl = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) dcl\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} dcl)\n\t\t-> let\n\t\t\ttypespecs = pd_typespecs lib mod dcl icl\n\t\t\tmacros = pd_macros lib mod dcl\n\t\t\tgetMacro n = case filter ((==) n o 'DB'.getName o fst) macros of\n\t\t\t\t[] = Nothing\n\t\t\t\t[(_,m):_] = Just m.macro_as_string\n\t\t\tupdateRepresentation n ('DB'.ET t te)\n\t\t\t\t= 'DB'.ET t {te & te_representation = getMacro n <|> te.te_representation}\n\t\tin ('DB'.Location lib mod (toLine class_pos) (findIclLine id_name =<< icl) id_name\n\t\t , map 'T'.toTypeVar class_args\n\t\t , flatten $ map 'T'.toClassContext class_context\n\t\t , [(f,updateRepresentation f et) \\\\ ('DB'.Location _ _ _ _ f, et) <- typespecs])) dcl\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [class_pos \\\\ PD_Class {class_ident,class_pos} _ <- pms | class_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_types :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod dcl icl\n\t\t= [let name = 'T'.td_name td in\n\t\t\t('DB'.Location lib mod (toLine ptd.td_pos) (findIclLine name =<< icl) name, td)\n\t\t \\\\ PD_Type ptd <- dcl, td <- ['T'.toTypeDef ptd]]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [td_pos \\\\ PD_Type {td_ident,td_pos} <- pms | td_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\n\treadModule :: Bool *DclCache *World -> *(Either String ParsedModule, *DclCache, *World)\n\treadModule icl cache w\n\t# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ if icl \".icl\" \".dcl\"\n\t# (ok,f,w) = fopen filename FReadText w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n\t cache = {cache & hash_table=ht}\n\t# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" icl mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n\t cache = {cache & hash_table=ht}\n\t# (ok,w) = fclose f w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t= (Right pm, cache, w)\n\nconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nconstructor_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\nconstructor_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\n\nprint_prio :: (Maybe 'T'.Priority) -> [String]\nprint_prio Nothing = []\nprint_prio (Just p) = [\" \"] ++ print False p\n\nrecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nrecord_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\nrecord_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"d421df6488496bf2cd83d7d2273638eb8bd0d5df","subject":"default icl","message":"default icl\n","repos":"mattgodbolt\/compiler-explorer,dkm\/gcc-explorer,mattgodbolt\/gcc-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/gcc-explorer,mattgodbolt\/compiler-explorer,dkm\/gcc-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/gcc-explorer,dkm\/gcc-explorer,dkm\/gcc-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/compiler-explorer,dkm\/gcc-explorer,mattgodbolt\/compiler-explorer,dkm\/gcc-explorer,dkm\/gcc-explorer,dkm\/gcc-explorer,mattgodbolt\/gcc-explorer,mattgodbolt\/gcc-explorer,dkm\/gcc-explorer","old_file":"examples\/clean\/default.icl","new_file":"examples\/clean\/default.icl","new_contents":"module example\n\nimport StdInt\n\nsumOverArray::[Int] -> Int\nsumOverArray [x:xs] = x + sumOverArray xs\nsumOverArray [] = 0\n\nStart = sumOverArray [1,3,4]\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'examples\/clean\/default.icl' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Clean"} {"commit":"5ca5b69755b0fbeedf013ac59456b8d62e15231e","subject":"Also store constructor functions of builtin types","message":"Also store constructor functions of builtin types\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/builddb.icl","new_file":"backend\/builddb.icl","new_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, ::Macro{..}, ::ModuleInfo{..},\n\tinstance zero TypeExtras, instance zero ModuleInfo\n\n\/\/ StdEnv\nfrom StdFunc import const, flip, o\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf,startsWith),\n\tinstance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String,\n\tinstance print Type, instance print Priority\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos,td_ident},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"ArgEnv\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"clean-platform\/OS-Independent\", const False)\n\t , (\"clean-platform\/OS-Linux\", const False)\n\t , (\"clean-platform\/OS-Linux-32\", const False)\n\t , (\"clean-platform\/OS-Linux-64\", const False)\n\t , (\"clean-platform\/OS-Mac\", const False)\n\t , (\"clean-platform\/OS-Posix\", const False)\n\t , (\"clean-platform\/OS-Windows\", const False)\n\t , (\"clean-platform\/OS-Windows-32\", const False)\n\t , (\"clean-platform\/OS-Windows-64\", const False)\n\t , (\"iTasks-SDK\/Dependencies\/graph_copy\", const False)\n\t , (\"iTasks-SDK\/Dependencies\/clean-sapl\/src\", const False)\n\t , (\"iTasks-SDK\/Server\", const False)\n\t , (\"iTasks-SDK\/Tests\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"SoccerFun\/Game\", const False)\n\t , (\"SoccerFun\/Gui\", const False)\n\t , (\"SoccerFun\/StdLibExt\", const False)\n\t , (\"SoccerFun\/StdReferee\", const False)\n\t , (\"SoccerFun\/StdTeam\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"clean-platform\/OS-Independent\/Deprecated\"\n\t , \"iTasks-SDK\/Server\/lib\"\n\t , \"SoccerFun\/StdReferee\/RefereeCoach_\"\n\t , \"SoccerFun\/StdTeam\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putClasses predefClasses db\n\t# db = 'DB'.putTypes predefTypes db\n\t# db = 'DB'.putFunctions (flatten $ map constructor_functions predefTypes) db\n\t# db = 'DB'.putFunctions (flatten $ map record_functions predefTypes) db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = 'DB'.saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] 'DB'.TypeDB\n\t\t*DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod,iscore):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib iscore cache db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !'DB'.TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ 'DB'.moduleCount db\n\t\t\t\t, 'DB'.functionCount db\n\t\t\t\t, 'DB'.macroCount db\n\t\t\t\t, 'DB'.typeCount db\n\t\t\t\t, 'DB'.classCount db\n\t\t\t\t, 'DB'.instanceCount db\n\t\t\t\t, 'DB'.deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t , ( 'DB'.Builtin \"dynamic\"\n\t , 'DB'.ET ('T'.Func ['T'.Var \"a\"] ('T'.Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext, [('DB'.Name, 'DB'.ExtendedType)])]\npredefClasses\n\t= [ ( 'DB'.Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"_#Array\" ['T'.Type \"Char\" []]) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[], 'Type'.cons_priority=Nothing}\n\n\/\/ Exclude Root Library Check for core Base module\nfindModules :: ![String] !String !'DB'.Library ('DB'.Module -> Bool) !String !*World\n\t-> *(![('DB'.Library, 'DB'.Module, Bool)], !*World)\nfindModules ex root lib iscore base w\n| any (\\e -> indexOf e path <> -1) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s -> let mod = basedot +++ s % (0, size s - 5) in\n\t(lib, mod, iscore mod)) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (\\d -> findModules ex root lib iscore (basedot +++ d)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any (\\e -> indexOf e (path +++ \"\/\" +++ s) <> -1) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String 'DB'.Module 'DB'.Library Bool\n\t*DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib iscore cache db w\n# (Right dcl,cache,w) = readModule False cache w\n# (icl,cache,w) = readModule True cache w\n# icl = case icl of (Left _) = Nothing; (Right x) = Just x\n# mod = dcl.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putFunctions (pd_typespecs lib mod dcl.mod_defs icl) db\n# db = 'DB'.putInstances (pd_instances lib mod dcl.mod_defs icl) db\n# db = 'DB'.putClasses (pd_classes lib mod dcl.mod_defs icl) db\n# typedefs = pd_types lib mod dcl.mod_defs icl\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib mod dcl.mod_defs) db\n# db = 'DB'.putDerivationss (pd_derivations lib mod dcl.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib mod dcl.mod_defs) db\n# db = 'DB'.putModule lib mod {zero & is_core=iscore} db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine pos) Nothing id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= 'T'.toMaybePriority}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- dcl]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id dcl of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id dcl\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):dcl]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:dcl] = findTypeSpec id dcl\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, 'DB'.Location)])]\n\tpd_derivations lib mod dcl\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, 'DB'.Location lib mod (toLine gc_pos) Nothing \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- dcl, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) Nothing id_name\n\t\t , 'DB'.ET ('T'.toType gen_type)\n\t\t {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars\n\t\t , te_representation=Just $ cpp gen}\n\t\t ) \\\\ gen=:(PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars}) <- dcl]\n\n\tpd_typespecs :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType t)\n\t\t { zero & te_priority = 'T'.toMaybePriority p\n\t\t , te_representation = Just $ cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pos \\\\ PD_TypeSpec pos id _ _ _ <- pms | id.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_instances :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Class, ['DB'.Type], 'DB'.Location)]\n\tpd_instances lib mod dcl icl\n\t\t= [( id_name\n\t\t , map 'T'.toType pi_types\n\t\t , 'DB'.Location lib mod (toLine pi_pos) (findIclLine id_name =<< icl) \"\"\n\t\t ) \\\\ PD_Instance {pim_pi={pi_ident={id_name},pi_types,pi_pos}} <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pi_pos \\\\ PD_Instance {pim_pi={pi_pos,pi_ident}} <- pms | pi_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_classes :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod dcl icl\n\t# dcl = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) dcl\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} dcl)\n\t\t-> let\n\t\t\ttypespecs = pd_typespecs lib mod dcl icl\n\t\t\tmacros = pd_macros lib mod dcl\n\t\t\tgetMacro n = case filter ((==) n o 'DB'.getName o fst) macros of\n\t\t\t\t[] = Nothing\n\t\t\t\t[(_,m):_] = Just m.macro_as_string\n\t\t\tupdateRepresentation n ('DB'.ET t te)\n\t\t\t\t= 'DB'.ET t {te & te_representation = getMacro n <|> te.te_representation}\n\t\tin ('DB'.Location lib mod (toLine class_pos) (findIclLine id_name =<< icl) id_name\n\t\t , map 'T'.toTypeVar class_args\n\t\t , flatten $ map 'T'.toClassContext class_context\n\t\t , [(f,updateRepresentation f et) \\\\ ('DB'.Location _ _ _ _ f, et) <- typespecs])) dcl\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [class_pos \\\\ PD_Class {class_ident,class_pos} _ <- pms | class_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_types :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod dcl icl\n\t\t= [let name = 'T'.td_name td in\n\t\t\t('DB'.Location lib mod (toLine ptd.td_pos) (findIclLine name =<< icl) name, td)\n\t\t \\\\ PD_Type ptd <- dcl, td <- ['T'.toTypeDef ptd]]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [td_pos \\\\ PD_Type {td_ident,td_pos} <- pms | td_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\n\treadModule :: Bool *DclCache *World -> *(Either String ParsedModule, *DclCache, *World)\n\treadModule icl cache w\n\t# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ if icl \".icl\" \".dcl\"\n\t# (ok,f,w) = fopen filename FReadText w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n\t cache = {cache & hash_table=ht}\n\t# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" icl mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n\t cache = {cache & hash_table=ht}\n\t# (ok,w) = fclose f w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t= (Right pm, cache, w)\n\nconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nconstructor_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\nconstructor_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\n\nprint_prio :: (Maybe 'T'.Priority) -> [String]\nprint_prio Nothing = []\nprint_prio (Just p) = [\" \"] ++ print False p\n\nrecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nrecord_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\nrecord_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","old_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, ::Macro{..}, ::ModuleInfo{..},\n\tinstance zero TypeExtras, instance zero ModuleInfo\n\n\/\/ StdEnv\nfrom StdFunc import const, flip, o\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf,startsWith),\n\tinstance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String,\n\tinstance print Type, instance print Priority\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos,td_ident},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"ArgEnv\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"clean-platform\/OS-Independent\", const False)\n\t , (\"clean-platform\/OS-Linux\", const False)\n\t , (\"clean-platform\/OS-Linux-32\", const False)\n\t , (\"clean-platform\/OS-Linux-64\", const False)\n\t , (\"clean-platform\/OS-Mac\", const False)\n\t , (\"clean-platform\/OS-Posix\", const False)\n\t , (\"clean-platform\/OS-Windows\", const False)\n\t , (\"clean-platform\/OS-Windows-32\", const False)\n\t , (\"clean-platform\/OS-Windows-64\", const False)\n\t , (\"iTasks-SDK\/Dependencies\/graph_copy\", const False)\n\t , (\"iTasks-SDK\/Dependencies\/clean-sapl\/src\", const False)\n\t , (\"iTasks-SDK\/Server\", const False)\n\t , (\"iTasks-SDK\/Tests\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"SoccerFun\/Game\", const False)\n\t , (\"SoccerFun\/Gui\", const False)\n\t , (\"SoccerFun\/StdLibExt\", const False)\n\t , (\"SoccerFun\/StdReferee\", const False)\n\t , (\"SoccerFun\/StdTeam\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"clean-platform\/OS-Independent\/Deprecated\"\n\t , \"iTasks-SDK\/Server\/lib\"\n\t , \"SoccerFun\/StdReferee\/RefereeCoach_\"\n\t , \"SoccerFun\/StdTeam\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putClasses predefClasses db\n\t# db = 'DB'.putTypes predefTypes db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = 'DB'.saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] 'DB'.TypeDB\n\t\t*DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod,iscore):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib iscore cache db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !'DB'.TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ 'DB'.moduleCount db\n\t\t\t\t, 'DB'.functionCount db\n\t\t\t\t, 'DB'.macroCount db\n\t\t\t\t, 'DB'.typeCount db\n\t\t\t\t, 'DB'.classCount db\n\t\t\t\t, 'DB'.instanceCount db\n\t\t\t\t, 'DB'.deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t , ( 'DB'.Builtin \"dynamic\"\n\t , 'DB'.ET ('T'.Func ['T'.Var \"a\"] ('T'.Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext, [('DB'.Name, 'DB'.ExtendedType)])]\npredefClasses\n\t= [ ( 'DB'.Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"_#Array\" ['T'.Type \"Char\" []]) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[], 'Type'.cons_priority=Nothing}\n\n\/\/ Exclude Root Library Check for core Base module\nfindModules :: ![String] !String !'DB'.Library ('DB'.Module -> Bool) !String !*World\n\t-> *(![('DB'.Library, 'DB'.Module, Bool)], !*World)\nfindModules ex root lib iscore base w\n| any (\\e -> indexOf e path <> -1) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s -> let mod = basedot +++ s % (0, size s - 5) in\n\t(lib, mod, iscore mod)) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (\\d -> findModules ex root lib iscore (basedot +++ d)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any (\\e -> indexOf e (path +++ \"\/\" +++ s) <> -1) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String 'DB'.Module 'DB'.Library Bool\n\t*DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib iscore cache db w\n# (Right dcl,cache,w) = readModule False cache w\n# (icl,cache,w) = readModule True cache w\n# icl = case icl of (Left _) = Nothing; (Right x) = Just x\n# mod = dcl.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putFunctions (pd_typespecs lib mod dcl.mod_defs icl) db\n# db = 'DB'.putInstances (pd_instances lib mod dcl.mod_defs icl) db\n# db = 'DB'.putClasses (pd_classes lib mod dcl.mod_defs icl) db\n# typedefs = pd_types lib mod dcl.mod_defs icl\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib mod dcl.mod_defs) db\n# db = 'DB'.putDerivationss (pd_derivations lib mod dcl.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib mod dcl.mod_defs) db\n# db = 'DB'.putModule lib mod {zero & is_core=iscore} db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine pos) Nothing id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= 'T'.toMaybePriority}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- dcl]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id dcl of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id dcl\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):dcl]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:dcl] = findTypeSpec id dcl\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, 'DB'.Location)])]\n\tpd_derivations lib mod dcl\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, 'DB'.Location lib mod (toLine gc_pos) Nothing \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- dcl, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) Nothing id_name\n\t\t , 'DB'.ET ('T'.toType gen_type)\n\t\t {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars\n\t\t , te_representation=Just $ cpp gen}\n\t\t ) \\\\ gen=:(PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars}) <- dcl]\n\n\tpd_typespecs :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType t)\n\t\t { zero & te_priority = 'T'.toMaybePriority p\n\t\t , te_representation = Just $ cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pos \\\\ PD_TypeSpec pos id _ _ _ <- pms | id.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_instances :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Class, ['DB'.Type], 'DB'.Location)]\n\tpd_instances lib mod dcl icl\n\t\t= [( id_name\n\t\t , map 'T'.toType pi_types\n\t\t , 'DB'.Location lib mod (toLine pi_pos) (findIclLine id_name =<< icl) \"\"\n\t\t ) \\\\ PD_Instance {pim_pi={pi_ident={id_name},pi_types,pi_pos}} <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pi_pos \\\\ PD_Instance {pim_pi={pi_pos,pi_ident}} <- pms | pi_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_classes :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod dcl icl\n\t# dcl = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) dcl\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} dcl)\n\t\t-> let\n\t\t\ttypespecs = pd_typespecs lib mod dcl icl\n\t\t\tmacros = pd_macros lib mod dcl\n\t\t\tgetMacro n = case filter ((==) n o 'DB'.getName o fst) macros of\n\t\t\t\t[] = Nothing\n\t\t\t\t[(_,m):_] = Just m.macro_as_string\n\t\t\tupdateRepresentation n ('DB'.ET t te)\n\t\t\t\t= 'DB'.ET t {te & te_representation = getMacro n <|> te.te_representation}\n\t\tin ('DB'.Location lib mod (toLine class_pos) (findIclLine id_name =<< icl) id_name\n\t\t , map 'T'.toTypeVar class_args\n\t\t , flatten $ map 'T'.toClassContext class_context\n\t\t , [(f,updateRepresentation f et) \\\\ ('DB'.Location _ _ _ _ f, et) <- typespecs])) dcl\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [class_pos \\\\ PD_Class {class_ident,class_pos} _ <- pms | class_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_types :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod dcl icl\n\t\t= [let name = 'T'.td_name td in\n\t\t\t('DB'.Location lib mod (toLine ptd.td_pos) (findIclLine name =<< icl) name, td)\n\t\t \\\\ PD_Type ptd <- dcl, td <- ['T'.toTypeDef ptd]]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [td_pos \\\\ PD_Type {td_ident,td_pos} <- pms | td_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tconstructor_functions ('DB'.Location lib mod line iclline _, td)\n\t\t= [('DB'.Location lib mod line iclline c, 'DB'.ET f\n\t\t\t{zero & te_isconstructor=True\n\t\t\t , te_representation=Just $ concat $\n\t\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t\t , te_priority=p})\n\t\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\n\twhere\n\t\tprint_prio :: (Maybe 'T'.Priority) -> [String]\n\t\tprint_prio Nothing = []\n\t\tprint_prio (Just p) = [\" \"] ++ print False p\n\n\trecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\trecord_functions ('DB'.Location lib mod line iclline _, td)\n\t\t= [('DB'.Location lib mod line iclline f, 'DB'.ET t\n\t\t\t{zero & te_isrecordfield=True\n\t\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\n\treadModule :: Bool *DclCache *World -> *(Either String ParsedModule, *DclCache, *World)\n\treadModule icl cache w\n\t# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ if icl \".icl\" \".dcl\"\n\t# (ok,f,w) = fopen filename FReadText w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n\t cache = {cache & hash_table=ht}\n\t# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" icl mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n\t cache = {cache & hash_table=ht}\n\t# (ok,w) = fclose f w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t= (Right pm, cache, w)\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"c98fc23a976b4df7127acc98ce29385b2d00b0a7","subject":"Process comments","message":"Process comments\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/Builtins.icl","new_file":"backend\/Builtins.icl","new_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [FunctionEntry]\nbuiltin_functions =\n\t[ { zero\n\t & fe_loc=Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []\n\t }\n\t, { zero\n\t & fe_loc=Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]\n\t }\n\t]\n\nbuiltin_classes :: [ClassEntry]\nbuiltin_classes =\n\t[ { ce_loc=Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , ce_vars=[\"v\"]\n\t , ce_is_meta=False\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t , ce_usages=[]\n\t }\n\t]\n\nbuiltin_types :: [TypeDefEntry]\nbuiltin_types =\n\t[ { deft\n\t & tde_loc=Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t, { deft & tde_loc=Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Int\"}\n\t, { deft & tde_loc=Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Real\"}\n\t, { deft & tde_loc=Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Char\"}\n\t, { deft & tde_loc=Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], tde_typedef.td_name = \"Dynamic\"}\n\t, { deft & tde_loc=Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"File\"}\n\t, { deft\n\t & tde_loc=Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"]\n\t , tde_typedef.td_name = \"String\"\n\t , tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) }\n\t, { deft\n\t & tde_loc=Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"World\"\n\t , tde_typedef.td_uniq = True\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\"\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"]\n\t , tde_typedef.td_name = \"(->)\"\n\t , tde_typedef.td_args = [Var \"a\", Var \"b\"]\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\"\n\t , vars = [\"The argument type\", \"The result type\"]\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"()\" []\n\t , tde_typedef.td_name=\"_Unit\"\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The void \/ unit type.\"\n\t }\n\t , tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]\n\t }\n\t: lists\n\t++ arrays\n\t++ tuples\n\t]\nwhere\n\tdeft =\n\t\t{ tde_loc=zero\n\t\t, tde_typedef=\n\t\t\t{ td_name=\"\"\n\t\t\t, td_uniq=False\n\t\t\t, td_args=[]\n\t\t\t, td_rhs=TDRAbstract Nothing\n\t\t\t}\n\t\t, tde_doc=Nothing\n\t\t, tde_instances=[]\n\t\t, tde_derivations=[]\n\t\t, tde_usages=[]\n\t\t}\n\tdefc =\n\t\t{ cons_name=\"\"\n\t\t, cons_args=[]\n\t\t, cons_exi_vars=[]\n\t\t, cons_context=[]\n\t\t, cons_priority=Nothing\n\t\t}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> TypeDefEntry\n\t\tmake_list k s =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the list elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> TypeDefEntry\n\t\tmake_array k =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the array elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> TypeDefEntry\n\t\tmake_tuple n =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"]\n\t\t\t, tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t\t\"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t\t\"Clean supports tuples of arity 2 to 32.\"\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows dlls.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked dlls according to the msvcrt file in Clean System Files.\"\n\t\t, \" \/\/ The file should start with the dll name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [FunctionEntry]\nbuiltin_functions =\n\t[ { zero\n\t & fe_loc=Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []\n\t }\n\t, { zero\n\t & fe_loc=Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]\n\t }\n\t]\n\nbuiltin_classes :: [ClassEntry]\nbuiltin_classes =\n\t[ { ce_loc=Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , ce_vars=[\"v\"]\n\t , ce_is_meta=False\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t , ce_usages=[]\n\t }\n\t]\n\nbuiltin_types :: [TypeDefEntry]\nbuiltin_types =\n\t[ { deft\n\t & tde_loc=Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t, { deft & tde_loc=Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Int\"}\n\t, { deft & tde_loc=Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Real\"}\n\t, { deft & tde_loc=Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Char\"}\n\t, { deft & tde_loc=Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], tde_typedef.td_name = \"Dynamic\"}\n\t, { deft & tde_loc=Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"File\"}\n\t, { deft\n\t & tde_loc=Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"]\n\t , tde_typedef.td_name = \"String\"\n\t , tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) }\n\t, { deft\n\t & tde_loc=Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"World\"\n\t , tde_typedef.td_uniq = True\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\"\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"]\n\t , tde_typedef.td_name = \"(->)\"\n\t , tde_typedef.td_args = [Var \"a\", Var \"b\"]\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\"\n\t , vars = [\"The argument type\", \"The result type\"]\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"()\" []\n\t , tde_typedef.td_name=\"_Unit\"\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The void \/ unit type.\"\n\t }\n\t , tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]\n\t }\n\t: lists\n\t++ arrays\n\t++ tuples\n\t]\nwhere\n\tdeft =\n\t\t{ tde_loc=zero\n\t\t, tde_typedef=\n\t\t\t{ td_name=\"\"\n\t\t\t, td_uniq=False\n\t\t\t, td_args=[]\n\t\t\t, td_rhs=TDRAbstract Nothing\n\t\t\t}\n\t\t, tde_doc=Nothing\n\t\t, tde_instances=[]\n\t\t, tde_derivations=[]\n\t\t, tde_usages=[]\n\t\t}\n\tdefc =\n\t\t{ cons_name=\"\"\n\t\t, cons_args=[]\n\t\t, cons_exi_vars=[]\n\t\t, cons_context=[]\n\t\t, cons_priority=Nothing\n\t\t}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> TypeDefEntry\n\t\tmake_list k s =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the list elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> TypeDefEntry\n\t\tmake_array k =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the array elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> TypeDefEntry\n\t\tmake_tuple n =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"]\n\t\t\t, tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t\t\"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t\t\"Clean supports tuples of arity 2 to 32.\"\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import ... qualified => ...\"\n\t\t, \"import code from library ...\"\n\t\t, \"import code from ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t\t\"Moreover, you can import from object files or windows dlls.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file starting called tty from Clean System Files.\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked dlls according to the msvcrt file in Clean System Files.\\nThe file should start with the dll name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"d1a1eaad383eba3e688857eb5324a923d27418fa","subject":"Remove Generics from index","message":"Remove Generics from index\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/builddb.icl","new_file":"backend\/builddb.icl","new_contents":"module builddb\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import const, id, o\nimport StdList\nimport StdMisc\nimport StdString\nimport StdTuple\n\nimport Data.Either\nfrom Data.Func import $, hyperstrict, mapSt\nimport Data.Functor\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nfrom Text import class Text(concat,startsWith), instance Text String\n\nimport CloogleDB\nimport Type\nfrom CloogleDBFactory import :: TemporaryDB, newTemporaryDB, finaliseDB,\n\tfindModules, indexModule, constructor_functions, record_functions\n\nimport Builtins\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String ModuleEntry -> ModuleEntry)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const id)\n\t , (\"CleanInotify\", const id)\n\t , (\"CleanPrettyPrint\", const id)\n\t , (\"CleanSerial\", const id)\n\t , (\"CleanSnappy\", const id)\n\t , (\"CleanTypeUnifier\", const id)\n\t , (\"Cloogle\", const id)\n\t , (\"Directory\", const id)\n\t , (\"Dynamics\", const id)\n\t , (\"Gast\", const id)\n\t , (\"GraphCopy\", const id)\n\t , (\"MersenneTwister\", const id)\n\t , (\"ObjectIO\", \\s me -> {me & me_is_core=not (startsWith \"Std\" s)})\n\t , (\"Platform\", const id)\n\t , (\"Sapl\", const id)\n\t , (\"SoccerFun\", const \\me -> {me & me_is_app=True})\n\t , (\"StdEnv\", const id)\n\t , (\"StdLib\", const id)\n\t , (\"TCPIP\", const id)\n\t , (\"iTasks\", const id)\n\t , (\"clean-compiler\", const \\me -> {me & me_is_app=True})\n\t , (\"clean-ide\", const \\me -> {me & me_is_app=True})\n\t , (\"libcloogle\", const id)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"Platform\/Deprecated\"\n\t , \"Platform\/Data\/Graph\/Inductive\/Query\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart :: *World -> *World\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t#! (db, w) = loop cli.root mods newTemporaryDB w\n\t#! db = finaliseDB builtins db\n\t#! (db,err) = printStats db stderr\n\t#! (ok1,w) = fclose err w\n\t#! (db,f) = saveDB db f\n\t#! (ok2,w) = fclose f w\n\t#! (_,dbg,w) = fopen \"typetree.dot\" FWriteText w\n\t#! (db,dbg) = writeTypeTree db dbg\n\t#! (_,w) = fclose dbg w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,String ModuleEntry -> ModuleEntry)] !TemporaryDB !*World -> *(!TemporaryDB, !*World)\n\tloop _ [] db w = (db,w)\n\tloop root [(lib,mod,modf):list] db w\n\t#! w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t#! (db, w) = indexModule False root mod lib modf db w\n\t#! db = hyperstrict db\n\t= loop root list db w\n\n\tbuiltins =\n\t\tmap FunctionEntry builtin_functions ++\n\t\tmap ClassEntry builtin_classes ++\n\t\tmap TypeDefEntry builtin_types ++\n\t\tmap FunctionEntry (concatMap constructor_functions builtin_types) ++\n\t\tmap FunctionEntry (concatMap record_functions builtin_types) ++\n\t\tmap SyntaxEntry builtin_syntax\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const id):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !*CloogleDB !*File -> *(*CloogleDB, *File)\n\tprintStats db f\n\t# (s,db) = dbStats db\n\t= (db, f\n\t\t<<< \"+-------------------+-------+\\n\"\n\t\t<< \"Modules\" <-- s.n_modules\n\t\t<< \"Functions\" <-- s.n_functions\n\t\t<< \"With types\" <-- s.n_functions_with_type\n\t\t<< \"Unique types\" <-- s.n_unique_types\n\t\t<< \"Type tree depth\" <-- s.type_tree_depth\n\t\t<< \"Type definitions\" <-- s.n_type_definitions\n\t\t<< \"Classes\" <-- s.n_classes\n\t\t<< \"Instances\" <-- s.n_instances\n\t\t<< \"Derivations\" <-- s.n_derivations\n\t\t<< \"Syntax constructs\" <-- s.n_syntax_constructs\n\t\t<<< \"+-------------------+-------+\\n\")\n\twhere\n\t\t(<<) infixl :: *File String -> *File\n\t\t(<<) f s = f <<< \"| \" <<< rpad 17 s <<< \" | \"\n\n\t\t(<--) infixl :: *File Int -> *File\n\t\t(<--) f i = f <<< lpad 5 i <<< \" |\\n\"\n\n\t\tlpad n s = {' ' \\\\ _ <- [0..n-size (toString s)-1]} +++ toString s\n\t\trpad n s = toString s +++ {' ' \\\\ _ <- [0..n-size (toString s)-1]}\n","old_contents":"module builddb\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import const, id, o\nimport StdList\nimport StdMisc\nimport StdString\nimport StdTuple\n\nimport Data.Either\nfrom Data.Func import $, hyperstrict, mapSt\nimport Data.Functor\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nfrom Text import class Text(concat,startsWith), instance Text String\n\nimport CloogleDB\nimport Type\nfrom CloogleDBFactory import :: TemporaryDB, newTemporaryDB, finaliseDB,\n\tfindModules, indexModule, constructor_functions, record_functions\n\nimport Builtins\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String ModuleEntry -> ModuleEntry)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const id)\n\t , (\"CleanInotify\", const id)\n\t , (\"CleanPrettyPrint\", const id)\n\t , (\"CleanSerial\", const id)\n\t , (\"CleanSnappy\", const id)\n\t , (\"CleanTypeUnifier\", const id)\n\t , (\"Cloogle\", const id)\n\t , (\"Directory\", const id)\n\t , (\"Dynamics\", const id)\n\t , (\"Gast\", const id)\n\t , (\"Generics\", const id)\n\t , (\"GraphCopy\", const id)\n\t , (\"MersenneTwister\", const id)\n\t , (\"ObjectIO\", \\s me -> {me & me_is_core=not (startsWith \"Std\" s)})\n\t , (\"Platform\", const id)\n\t , (\"Sapl\", const id)\n\t , (\"SoccerFun\", const \\me -> {me & me_is_app=True})\n\t , (\"StdEnv\", const id)\n\t , (\"StdLib\", const id)\n\t , (\"TCPIP\", const id)\n\t , (\"iTasks\", const id)\n\t , (\"clean-compiler\", const \\me -> {me & me_is_app=True})\n\t , (\"clean-ide\", const \\me -> {me & me_is_app=True})\n\t , (\"libcloogle\", const id)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"Platform\/Deprecated\"\n\t , \"Platform\/Data\/Graph\/Inductive\/Query\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart :: *World -> *World\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t#! (db, w) = loop cli.root mods newTemporaryDB w\n\t#! db = finaliseDB builtins db\n\t#! (db,err) = printStats db stderr\n\t#! (ok1,w) = fclose err w\n\t#! (db,f) = saveDB db f\n\t#! (ok2,w) = fclose f w\n\t#! (_,dbg,w) = fopen \"typetree.dot\" FWriteText w\n\t#! (db,dbg) = writeTypeTree db dbg\n\t#! (_,w) = fclose dbg w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,String ModuleEntry -> ModuleEntry)] !TemporaryDB !*World -> *(!TemporaryDB, !*World)\n\tloop _ [] db w = (db,w)\n\tloop root [(lib,mod,modf):list] db w\n\t#! w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t#! (db, w) = indexModule False root mod lib modf db w\n\t#! db = hyperstrict db\n\t= loop root list db w\n\n\tbuiltins =\n\t\tmap FunctionEntry builtin_functions ++\n\t\tmap ClassEntry builtin_classes ++\n\t\tmap TypeDefEntry builtin_types ++\n\t\tmap FunctionEntry (concatMap constructor_functions builtin_types) ++\n\t\tmap FunctionEntry (concatMap record_functions builtin_types) ++\n\t\tmap SyntaxEntry builtin_syntax\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const id):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !*CloogleDB !*File -> *(*CloogleDB, *File)\n\tprintStats db f\n\t# (s,db) = dbStats db\n\t= (db, f\n\t\t<<< \"+-------------------+-------+\\n\"\n\t\t<< \"Modules\" <-- s.n_modules\n\t\t<< \"Functions\" <-- s.n_functions\n\t\t<< \"With types\" <-- s.n_functions_with_type\n\t\t<< \"Unique types\" <-- s.n_unique_types\n\t\t<< \"Type tree depth\" <-- s.type_tree_depth\n\t\t<< \"Type definitions\" <-- s.n_type_definitions\n\t\t<< \"Classes\" <-- s.n_classes\n\t\t<< \"Instances\" <-- s.n_instances\n\t\t<< \"Derivations\" <-- s.n_derivations\n\t\t<< \"Syntax constructs\" <-- s.n_syntax_constructs\n\t\t<<< \"+-------------------+-------+\\n\")\n\twhere\n\t\t(<<) infixl :: *File String -> *File\n\t\t(<<) f s = f <<< \"| \" <<< rpad 17 s <<< \" | \"\n\n\t\t(<--) infixl :: *File Int -> *File\n\t\t(<--) f i = f <<< lpad 5 i <<< \" |\\n\"\n\n\t\tlpad n s = {' ' \\\\ _ <- [0..n-size (toString s)-1]} +++ toString s\n\t\trpad n s = toString s +++ {' ' \\\\ _ <- [0..n-size (toString s)-1]}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"ad3a1959cb49cdee765019d7af18951741bb862f","subject":"Add the qualified hiding syntax construct","message":"Add the qualified hiding syntax construct\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"backend\/Builtins.icl","new_file":"backend\/Builtins.icl","new_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [FunctionEntry]\nbuiltin_functions =\n\t[ { zero\n\t & fe_loc=Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []\n\t }\n\t, { zero\n\t & fe_loc=Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]\n\t }\n\t]\n\nbuiltin_classes :: [ClassEntry]\nbuiltin_classes =\n\t[ { ce_loc=Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , ce_vars=[\"v\"]\n\t , ce_is_meta=False\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t , ce_usages=[]\n\t }\n\t]\n\nbuiltin_types :: [TypeDefEntry]\nbuiltin_types =\n\t[ { deft\n\t & tde_loc=Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t, { deft & tde_loc=Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Int\"}\n\t, { deft & tde_loc=Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Real\"}\n\t, { deft & tde_loc=Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Char\"}\n\t, { deft & tde_loc=Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], tde_typedef.td_name = \"Dynamic\"}\n\t, { deft & tde_loc=Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"File\"}\n\t, { deft\n\t & tde_loc=Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"]\n\t , tde_typedef.td_name = \"String\"\n\t , tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) }\n\t, { deft\n\t & tde_loc=Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"World\"\n\t , tde_typedef.td_uniq = True\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\"\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"]\n\t , tde_typedef.td_name = \"(->)\"\n\t , tde_typedef.td_args = [Var \"a\", Var \"b\"]\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\"\n\t , vars = [\"The argument type\", \"The result type\"]\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"()\" []\n\t , tde_typedef.td_name=\"_Unit\"\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The void \/ unit type.\"\n\t }\n\t , tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]\n\t }\n\t: lists\n\t++ arrays\n\t++ tuples\n\t]\nwhere\n\tdeft =\n\t\t{ tde_loc=zero\n\t\t, tde_typedef=\n\t\t\t{ td_name=\"\"\n\t\t\t, td_uniq=False\n\t\t\t, td_args=[]\n\t\t\t, td_rhs=TDRAbstract Nothing\n\t\t\t}\n\t\t, tde_doc=Nothing\n\t\t, tde_instances=[]\n\t\t, tde_derivations=[]\n\t\t, tde_usages=[]\n\t\t}\n\tdefc =\n\t\t{ cons_name=\"\"\n\t\t, cons_args=[]\n\t\t, cons_exi_vars=[]\n\t\t, cons_context=[]\n\t\t, cons_priority=Nothing\n\t\t}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> TypeDefEntry\n\t\tmake_list k s =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the list elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> TypeDefEntry\n\t\tmake_array k =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the array elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> TypeDefEntry\n\t\tmake_tuple n =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"]\n\t\t\t, tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t\t\"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t\t\"Clean supports tuples of arity 2 to 32.\"\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... qualified => ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [FunctionEntry]\nbuiltin_functions =\n\t[ { zero\n\t & fe_loc=Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []\n\t }\n\t, { zero\n\t & fe_loc=Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]\n\t }\n\t]\n\nbuiltin_classes :: [ClassEntry]\nbuiltin_classes =\n\t[ { ce_loc=Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , ce_vars=[\"v\"]\n\t , ce_is_meta=False\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t , ce_usages=[]\n\t }\n\t]\n\nbuiltin_types :: [TypeDefEntry]\nbuiltin_types =\n\t[ { deft\n\t & tde_loc=Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t, { deft & tde_loc=Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Int\"}\n\t, { deft & tde_loc=Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Real\"}\n\t, { deft & tde_loc=Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Char\"}\n\t, { deft & tde_loc=Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], tde_typedef.td_name = \"Dynamic\"}\n\t, { deft & tde_loc=Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"File\"}\n\t, { deft\n\t & tde_loc=Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"]\n\t , tde_typedef.td_name = \"String\"\n\t , tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) }\n\t, { deft\n\t & tde_loc=Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"World\"\n\t , tde_typedef.td_uniq = True\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\"\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"]\n\t , tde_typedef.td_name = \"(->)\"\n\t , tde_typedef.td_args = [Var \"a\", Var \"b\"]\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\"\n\t , vars = [\"The argument type\", \"The result type\"]\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"()\" []\n\t , tde_typedef.td_name=\"_Unit\"\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The void \/ unit type.\"\n\t }\n\t , tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]\n\t }\n\t: lists\n\t++ arrays\n\t++ tuples\n\t]\nwhere\n\tdeft =\n\t\t{ tde_loc=zero\n\t\t, tde_typedef=\n\t\t\t{ td_name=\"\"\n\t\t\t, td_uniq=False\n\t\t\t, td_args=[]\n\t\t\t, td_rhs=TDRAbstract Nothing\n\t\t\t}\n\t\t, tde_doc=Nothing\n\t\t, tde_instances=[]\n\t\t, tde_derivations=[]\n\t\t, tde_usages=[]\n\t\t}\n\tdefc =\n\t\t{ cons_name=\"\"\n\t\t, cons_args=[]\n\t\t, cons_exi_vars=[]\n\t\t, cons_context=[]\n\t\t, cons_priority=Nothing\n\t\t}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> TypeDefEntry\n\t\tmake_list k s =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the list elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> TypeDefEntry\n\t\tmake_array k =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the array elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> TypeDefEntry\n\t\tmake_tuple n =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"]\n\t\t\t, tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t\t\"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t\t\"Clean supports tuples of arity 2 to 32.\"\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\"]\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"b4d7cb3f5bae3f1e9e88c731ae23181293de5aa3","subject":"Add unique variables and dot notation","message":"Add unique variables and dot notation\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \"[\", \"]\", \".\"]\n\t, syntax_code =\n\t\t[\"*...\"\n\t\t,\". ...\" \n\t\t,\"v ... | [v ..]\" \n\t, syntax_description = \"Annotates a type with its uniqueness. A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [..]`). Note that when using unique types in a function or an ADT the container must also be unique. e.g. `T = T (Int, *File)` has to be `T = T *(Int, *File)`. Functions have to be split up into arity 1 and the sub functions need to be annotated as well. e.g. `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/World is unique\"\n\t\t, \"f :: .a -> .a \/\/f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\"]\n\t, syntax_code = [\"*...\"]\n\t, syntax_description = \"Annotates a type to be unique.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"83f4a4b6c3424792667ee30cce89e1157efc6453","subject":"Fix order of cache reevaluation","message":"Fix order of cache reevaluation\n","repos":"dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o, seq\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable, instance Foldable Maybe\nfrom Data.Func import $, hyperstrict\nimport Data.Functor\nimport Data.List\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_include_apps = fromJust (r.include_apps <|> Just DEFAULT_INCLUDE_APPS)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDb f\n#! db = hyperstrict db\n#! w = if opts.reload_cache (doInBackground (reloadCache db)) id w\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle db\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !CloogleDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle db Nothing w = (err InvalidInput \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond {r & return = if (r.return == 0) 1 r.return} w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err InvalidName \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err InvalidName \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err InvalidType \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! results = drop drop_n $ sort $ search request db\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! suggestions = unify >>= parseType o fromString >>= flip (suggs name) db\n\t\t#! w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- 'Foldable'.concat suggestions] w\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: !Response !*World -> *(!Response, !CacheKey, !*World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !CloogleDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\treloadCache :: !CloogleDB -> *World -> *World\n\treloadCache db = uncurry (flip (foldl (flip search))) o allCacheKeys LongTerm\n\twhere\n\t\tsearch :: !RequestCacheKey -> *World -> *World\n\t\tsearch r = thd3 o handle db (Just $ fromRequestCacheKey r) o removeFromCache LongTerm r\n\n\tdoInBackground :: (*World -> *World) *World -> *World\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o, seq\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable, instance Foldable Maybe\nfrom Data.Func import $, hyperstrict\nimport Data.Functor\nimport Data.List\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_include_apps = fromJust (r.include_apps <|> Just DEFAULT_INCLUDE_APPS)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDb f\n#! db = hyperstrict db\n#! w = if opts.reload_cache (doInBackground (reloadCache db)) id w\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle db\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !CloogleDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle db Nothing w = (err InvalidInput \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond {r & return = if (r.return == 0) 1 r.return} w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err InvalidName \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err InvalidName \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err InvalidType \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! results = drop drop_n $ sort $ search request db\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! suggestions = unify >>= parseType o fromString >>= flip (suggs name) db\n\t\t#! w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- 'Foldable'.concat suggestions] w\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: !Response !*World -> *(!Response, !CacheKey, !*World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !CloogleDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\treloadCache :: !CloogleDB -> *World -> *World\n\treloadCache db = uncurry (flip (foldr search)) o allCacheKeys LongTerm\n\twhere\n\t\tsearch :: !RequestCacheKey -> *World -> *World\n\t\tsearch r = thd3 o handle db (Just $ fromRequestCacheKey r) o removeFromCache LongTerm r\n\n\tdoInBackground :: (*World -> *World) *World -> *World\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"7a10fe148fee31d9eb585e8ab67e819a9f453139","subject":"Fix cache","message":"Fix cache\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nimport StdList\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Tuple\nimport Data.Maybe\nimport System.CommandLine\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\nimport Text.JSON\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\nimport Cloogle\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe ([String], Bool)\n\t , c_page :: Maybe Int\n\t }\n\nderive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = appFst sort <$> r.libraries\n\t, c_page = r.page\n\t}\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle _ Nothing w = (err CLOOGLE_E_INVALIDINPUT \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey request, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err CLOOGLE_E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err CLOOGLE_E_NORESULTS \"No results\")\n\t\t\t{ return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: Response *World -> *(Response, CacheKey, *World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: Int Int Response [Result] *World -> *World\n\t\tcachePages _ _ _ [] w = w\n\t\tcachePages 0 _ _ _ w = w\n\t\tcachePages npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = ((+) i) <$> (key.c_page <|> pure 0) }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n (Location lib mod Nothing Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line iclline cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line iclline f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\loc _ _ _ -> toLowerCase (getName loc) == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line iclline cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" | \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [([concat (print False t) \\\\ t <- ts], map loc ls)\n\t\t \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line iclline t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line iclline m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,iclline,builtin) = case fl of\n\t\t\t(Location l m ln iln f) = (l, m, f, ln, iln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln iln _) = (lib, mod, ln, iln)\n\n\tlog :: (LogMessage (Maybe Request) Response CacheKey) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _ _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available} ck) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg\n\t\t\t+ if (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\"\n\t\t\t+ \"; cache: \" + ck + \")\\n\"\n\tmsgToString _ _ = \"\"\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nimport StdList\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Tuple\nimport Data.Maybe\nimport System.CommandLine\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\nimport Text.JSON\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\nimport Cloogle\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe ([String], Bool)\n\t , c_page :: Maybe Int\n\t }\n\nderive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = appFst sort <$> r.libraries\n\t, c_page = r.page\n\t}\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle _ Nothing w = (err CLOOGLE_E_INVALIDINPUT \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache request w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey request, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err CLOOGLE_E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err CLOOGLE_E_NORESULTS \"No results\")\n\t\t\t{ return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: Response *World -> *(Response, CacheKey, *World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: Int Int Response [Result] *World -> *World\n\t\tcachePages _ _ _ [] w = w\n\t\tcachePages 0 _ _ _ w = w\n\t\tcachePages npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = ((+) i) <$> (key.c_page <|> pure 0) }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n (Location lib mod Nothing Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line iclline cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line iclline f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\loc _ _ _ -> toLowerCase (getName loc) == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line iclline cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" | \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [([concat (print False t) \\\\ t <- ts], map loc ls)\n\t\t \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line iclline t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line iclline m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,iclline,builtin) = case fl of\n\t\t\t(Location l m ln iln f) = (l, m, f, ln, iln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln iln _) = (lib, mod, ln, iln)\n\n\tlog :: (LogMessage (Maybe Request) Response CacheKey) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _ _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available} ck) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg\n\t\t\t+ if (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\"\n\t\t\t+ \"; cache: \" + ck + \")\\n\"\n\tmsgToString _ _ = \"\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"9b402b2040d698adc4c3a8cac7cebd5e384c0231","subject":"Document push_a_b ABC instruction","message":"Document push_a_b ABC instruction\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/ABC.icl","new_file":"backend\/Builtin\/ABC.icl","new_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t, i_push_a_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\ti_push_a_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a_b\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET]\n\t\t, aie_description = \"Pushes the A-stack element as an integer (i.e., a pointer to the heap) on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t, i_push_r_arg_t\n\t, i_push_t_r_a\n\t, i_push_t_r_args\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \" - sep can be either `-` or `:`.\"\n\t\t\t, \" - flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \" - input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t\t, \" - output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t\t, \" - state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \" - `I` for integers\"\n\t\t\t, \" - `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \" - [`Rr`] for reals\"\n\t\t\t, \" - `S` for Clean Strings (`{#Char}`). If used as input type this passes a pointer to the string's length (number of characters). The actual array is at offset 4\/8 (32\/64 bit). If this is used as output type, the C function has to return a pointer to the string's length, followed by the actual string. A copy of the string will be created in the Clean heap, and this copy will be used by Clean. If the string was allocated in C, for example using malloc, it should be deallocated in C when it no longer used, it is not automatically deallocated by Clean.\"\n\t\t\t, \" - `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}}, as the string is not null-terminated). The length (number of characters) is at offset -4\/-8. (32\/64 bit).\"\n\t\t\t, \" - `A` for A-stack elements. A pointer to the third block of the node is passed. For arrays, this is a pointer to the elements. The size of the array is one word higher in the block.\"\n\t\t\t, \" - [`OF`] for function pointers\"\n\t\t\t, \" - `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\n\ti_push_r_arg_t =\n\t\t{ zero\n\t\t& aie_instruction = \"push_r_arg_t\"\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Gets the *n*th element from the type string of a record.\"\n\t\t\t, \"The type string is on top of the B-stack; *n* below that.\"\n\t\t\t]\n\t\t}\n\ti_push_t_r_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Push the address of the type string of the referenced record to the B-stack.\"\n\t\t}\n\ti_push_t_r_args =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_args\"\n\t\t, aie_description = \"Pops a record from the A-stack, pushes its members in reversed order to both of the stacks, then pushes the address of the type string to the B-stack.\"\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_n\n\t, d_nu\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_n =\n\t\t{ zero\n\t\t& aie_instruction = \".n\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t, \"\\n\\nThere are some special cases:\\n\\n\"\n\t\t\t, \"- An arity of `-1` is for tuple selectors;\\n\"\n\t\t\t, \"- An arity of `-2` is for indirection nodes;\\n\"\n\t\t\t, \"- An arity of `-3` is for record selectors of basic types;\\n\"\n\t\t\t, \"- An arity of `-4` is for record selectors of non-basic types.\\n\\n\"\n\t\t\t, \"See also {{`.nu`}}.\"\n\t\t\t]\n\t\t}\n\td_nu =\n\t\t{ zero\n\t\t& aie_instruction = \".nu\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels with arguments on the B-stack (otherwise, {{`.n`}} is used).\"\n\t\t\t, \"The first integer is the number of A-stack arguments; the second the number of B-stack arguments.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","old_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t, i_push_r_arg_t\n\t, i_push_t_r_a\n\t, i_push_t_r_args\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \" - sep can be either `-` or `:`.\"\n\t\t\t, \" - flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \" - input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t\t, \" - output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t\t, \" - state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \" - `I` for integers\"\n\t\t\t, \" - `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \" - [`Rr`] for reals\"\n\t\t\t, \" - `S` for Clean Strings (`{#Char}`). If used as input type this passes a pointer to the string's length (number of characters). The actual array is at offset 4\/8 (32\/64 bit). If this is used as output type, the C function has to return a pointer to the string's length, followed by the actual string. A copy of the string will be created in the Clean heap, and this copy will be used by Clean. If the string was allocated in C, for example using malloc, it should be deallocated in C when it no longer used, it is not automatically deallocated by Clean.\"\n\t\t\t, \" - `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}}, as the string is not null-terminated). The length (number of characters) is at offset -4\/-8. (32\/64 bit).\"\n\t\t\t, \" - `A` for A-stack elements. A pointer to the third block of the node is passed. For arrays, this is a pointer to the elements. The size of the array is one word higher in the block.\"\n\t\t\t, \" - [`OF`] for function pointers\"\n\t\t\t, \" - `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\n\ti_push_r_arg_t =\n\t\t{ zero\n\t\t& aie_instruction = \"push_r_arg_t\"\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Gets the *n*th element from the type string of a record.\"\n\t\t\t, \"The type string is on top of the B-stack; *n* below that.\"\n\t\t\t]\n\t\t}\n\ti_push_t_r_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Push the address of the type string of the referenced record to the B-stack.\"\n\t\t}\n\ti_push_t_r_args =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_args\"\n\t\t, aie_description = \"Pops a record from the A-stack, pushes its members in reversed order to both of the stacks, then pushes the address of the type string to the B-stack.\"\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_n\n\t, d_nu\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_n =\n\t\t{ zero\n\t\t& aie_instruction = \".n\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t, \"\\n\\nThere are some special cases:\\n\\n\"\n\t\t\t, \"- An arity of `-1` is for tuple selectors;\\n\"\n\t\t\t, \"- An arity of `-2` is for indirection nodes;\\n\"\n\t\t\t, \"- An arity of `-3` is for record selectors of basic types;\\n\"\n\t\t\t, \"- An arity of `-4` is for record selectors of non-basic types.\\n\\n\"\n\t\t\t, \"See also {{`.nu`}}.\"\n\t\t\t]\n\t\t}\n\td_nu =\n\t\t{ zero\n\t\t& aie_instruction = \".nu\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels with arguments on the B-stack (otherwise, {{`.n`}} is used).\"\n\t\t\t, \"The first integer is the number of A-stack arguments; the second the number of B-stack arguments.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_a_b\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"470116afa32ee6a4f64ccf5cc4da527d740cc177","subject":"Add eadts to syntax builtins","message":"Add eadts to syntax builtins\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_eadt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_eadt =\n\t{ syntax_title = \"extensible algebraic data types\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ..\", \":: T = ..\"]\n\t, syntax_description = \"Extensible algebraic data types are ADT's that can be extended in other modules. One module can declare the ADT as extendible by adding the .. constructior. Other modules can then extend it. It is not possible to derive functions for EADTs\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\"]\n\t, syntax_code = [\"*...\"]\n\t, syntax_description = \"Annotates a type to be unique.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\"]\n\t, syntax_code = [\"*...\"]\n\t, syntax_description = \"Annotates a type to be unique.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"3276f27fa24a421a015e73d268a8e91e7aadde74","subject":"Typo","message":"Typo\n\ngit-svn-id: 152f48a1866dc7886cc2b83d2001e6645df26423@1004098 13f79535-47bb-0310-9956-ffa450edef68\n","repos":"mohanaraosv\/commons-exec,sgoeschl\/commons-exec,mohanaraosv\/commons-exec,apache\/commons-exec,sgoeschl\/commons-exec,apache\/commons-exec","old_file":"src\/test\/scripts\/stdin.dcl","new_file":"src\/test\/scripts\/stdin.dcl","new_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Licensed to the Apache Software Foundation (ASF) under one or more\n$! contributor license agreements. See the NOTICE file distributed with\n$! this work for additional information regarding copyright ownership.\n$! The ASF licenses this file to You under the Apache License, Version 2.0\n$! (the \"License\"); you may not use this file except in compliance with\n$! the License. You may obtain a copy of the License at\n$!\n$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n$!\n$! Unless required by applicable law or agreed to in writing, software\n$! distributed under the License is distributed on an \"AS IS\" BASIS,\n$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n$! See the License for the specific language governing permissions and\n$! limitations under the License.\n$! \n$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Read input and display is\n$!\n$ read \/prompt=\"What's your name? : \" sys$command answer\n$ write sys$output \"Hello ''answer'!\"","old_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Licensed to the Apache Software Foundation (ASF) under one or more\n$! contributor license agreements. See the NOTICE file distributed with\n$! this work for additional information regarding copyright ownership.\n$! The ASF licenses this file to You under the Apache License, Version 2.0\n$! (the \"License\"); you may not use this file except in compliance with\n$! the License. You may obtain a copy of the License at\n$!\n$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n$!\n$! Unless required by applicable law or agreed to in writing, software\n$! distributed under the License is distributed on an \"AS IS\" BASIS,\n$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n$! See the License for the specific language governing permissions and\n$! limitations under the License.\n$! \n$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Read input and display is\n$!\n$ read \/prompt=\"What's your name? : \" sys$command answer\n$ write sys$output \"Hello ''answer'\"","returncode":0,"stderr":"","license":"apache-2.0","lang":"Clean"} {"commit":"c0805cd8d459f8b2056ae8d2fcb97e515f7e1f9a","subject":"*** empty log message ***","message":"*** empty log message ***\n","repos":"kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout","old_file":"bench\/harmonic\/harmonic.icl","new_file":"bench\/harmonic\/harmonic.icl","new_contents":"\/* The Great Win32 Computer Language Shootout \n http:\/\/dada.perl.it\/shootout\/\n\n contributed by Isaac Gouy (Clean novice)\n*\/\n\n\nmodule harmonic\nimport StdEnv, LanguageShootout\n\nStart = toStringWith 9 (loop argi 0.0 0.0)\n\nloop :: !Int !Real !Real -> Real\nloop i d sum \n | i > 0 = loop (i-1) d` (s + (1.0\/d`)) \n | otherwise = sum\n where d` = d + 1.0","old_contents":"","returncode":1,"stderr":"error: pathspec 'bench\/harmonic\/harmonic.icl' did not match any file(s) known to git\n","license":"bsd-3-clause","lang":"Clean"} {"commit":"acebe8b3f3a2629485a6bd0ebaa92ccbcd3275a0","subject":"Fix showing types of constructors and record fields","message":"Fix showing types of constructors and record fields\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle","old_file":"backend\/builddb.icl","new_file":"backend\/builddb.icl","new_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, instance zero TypeExtras, ::Macro{..}\n\n\/\/ StdEnv\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf), instance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String, instance print Type\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [String]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ \"StdEnv\"\n\t , \"StdLib\"\n\t , \"ArgEnv\"\n\t , \"Directory\"\n\t , \"Dynamics\"\n\t , \"Gast\"\n\t , \"Generics\"\n\t , \"MersenneTwister\"\n\t , \"TCPIP\"\n\t , \"clean-platform\/OS-Independent\"\n\t , \"clean-platform\/OS-Linux\"\n\t , \"clean-platform\/OS-Linux-32\"\n\t , \"clean-platform\/OS-Linux-64\"\n\t , \"clean-platform\/OS-Mac\"\n\t , \"clean-platform\/OS-Posix\"\n\t , \"clean-platform\/OS-Windows\"\n\t , \"clean-platform\/OS-Windows-32\"\n\t , \"clean-platform\/OS-Windows-64\"\n\t , \"iTasks-SDK\/Dependencies\/graph_copy\"\n\t , \"iTasks-SDK\/Dependencies\/clean-sapl\/src\"\n\t , \"iTasks-SDK\/Server\"\n\t , \"iTasks-SDK\/Tests\"\n\t , \"SoccerFun\/Game\"\n\t , \"SoccerFun\/Gui\"\n\t , \"SoccerFun\/StdLibExt\"\n\t , \"SoccerFun\/StdReferee\"\n\t , \"SoccerFun\/StdTeam\"\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"clean-platform\/OS-Independent\/Deprecated\"\n\t , \"iTasks-SDK\/Server\/lib\"\n\t , \"SoccerFun\/StdReferee\/RefereeCoach_\"\n\t , \"SoccerFun\/StdTeam\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (\\l -> findModules cli.exclude cli.root l \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putTypes predefTypes db\n\t# f = 'DB'.saveDb db f\n\t= fclose f w\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String)] 'DB'.TypeDB *DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib cache db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[x:c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t\t\t]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"{#Char}\" []) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[]}\n\n\/\/ Exclude Root Library Base module Library Module\nfindModules :: ![String] !String !String !String !*World -> *(![(String,String)], !*World)\nfindModules ex root lib base w\n| any (\\e -> indexOf e path <> -1) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s -> (lib, basedot +++ s % (0, size s - 5))) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (\\d -> findModules ex root lib (basedot +++ d)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any (\\e -> indexOf e (path +++ \"\/\" +++ s) <> -1) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String String String *DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib cache db w\n# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ \".dcl\"\n# (ok,f,w) = fopen filename FReadText w\n| not ok = abort (\"Couldn't open file \" +++ filename +++ \".\\n\")\n# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n cache = {cache & hash_table=ht}\n# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" False mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n cache = {cache & hash_table=ht}\n# (ok,w) = fclose f w\n| not ok = abort (\"Couldn't close file \" +++ filename +++ \".\\n\")\n# mod = pm.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putFunctions (pd_typespecs lib mod pm.mod_defs) db\n# db = 'DB'.putInstancess (pd_instances lib mod pm.mod_defs) db\n# db = 'DB'.putClasses (pd_classes lib mod pm.mod_defs) db\n# typedefs = pd_types lib mod pm.mod_defs\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib mod pm.mod_defs) db\n# db = 'DB'.putDerivationss (pd_derivations lib mod pm.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib mod pm.mod_defs) db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod pds\n\t\t= [( 'DB'.Location lib mod (toLine pos) id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= toPrio}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- pds]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id pds of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id pds\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):pds]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:pds] = findTypeSpec id pds\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, 'DB'.Location)])]\n\tpd_derivations lib mod pds\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, 'DB'.Location lib mod (toLine gc_pos) \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- pds, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod pds\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) id_name\n\t\t , 'DB'.ET ('T'.toType gen_type) {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars}\n\t\t ) \\\\ PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars} <- pds]\n\n\tpd_typespecs :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod pds\n\t\t= [( 'DB'.Location lib mod (toLine pos) id_name\n\t\t , 'DB'.ET ('T'.toType t) {zero & te_priority=toPrio p, te_representation=cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- pds]\n\n\tpd_instances :: String String [ParsedDefinition]\n\t\t-> [('DB'.Class, [('DB'.Type, 'DB'.Location)])]\n\tpd_instances lib mod pds\n\t\t= [( pi_ident.id_name\n\t\t , [('T'.toType t, 'DB'.Location lib mod (toLine pi_pos) \"\") \\\\ t <- pi_types]\n\t\t ) \\\\ PD_Instance {pim_pi={pi_ident,pi_types,pi_pos}} <- pds]\n\n\tpd_classes :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod pds\n\t# pds = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) pds\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} pds)\n\t\t-> let typespecs = pd_typespecs lib mod pds\n\t\tin ('DB'.Location lib mod (toLine class_pos) id_name, map 'T'.toTypeVar class_args,\n\t\t flatten $ map 'T'.toClassContext class_context,\n\t\t [(f,et) \\\\ ('DB'.Location _ _ _ f, et) <- typespecs])) pds\n\n\tpd_types :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod pds\n\t\t= [('DB'.Location lib mod (toLine ptd.td_pos) ('T'.td_name td), td)\n\t\t \\\\ PD_Type ptd <- pds, td <- ['T'.toTypeDef ptd]]\n\n\tconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tconstructor_functions ('DB'.Location lib mod line _, td)\n\t\t= [('DB'.Location lib mod line c, 'DB'.ET f\n\t\t\t{zero & te_isconstructor=True, te_representation=concat $ [c, \" :: \" : print False f]})\n\t\t \\\\ (c,f) <- 'T'.constructorsToFunctions td]\n\n\trecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\trecord_functions ('DB'.Location lib mod line _, td)\n\t\t= [('DB'.Location lib mod line f, 'DB'.ET t\n\t\t\t{zero & te_isrecordfield=True, te_representation=concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\n\ttoPrio :: Priority -> Maybe 'DB'.TE_Priority\n\ttoPrio (Prio LeftAssoc i) = Just $ 'DB'.LeftAssoc i\n\ttoPrio (Prio RightAssoc i) = Just $ 'DB'.RightAssoc i\n\ttoPrio (Prio NoAssoc i) = Just $ 'DB'.NoAssoc i\n\ttoPrio _ = Nothing\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","old_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, instance zero TypeExtras, ::Macro{..}\n\n\/\/ StdEnv\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf), instance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [String]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ \"StdEnv\"\n\t , \"StdLib\"\n\t , \"ArgEnv\"\n\t , \"Directory\"\n\t , \"Dynamics\"\n\t , \"Gast\"\n\t , \"Generics\"\n\t , \"MersenneTwister\"\n\t , \"TCPIP\"\n\t , \"clean-platform\/OS-Independent\"\n\t , \"clean-platform\/OS-Linux\"\n\t , \"clean-platform\/OS-Linux-32\"\n\t , \"clean-platform\/OS-Linux-64\"\n\t , \"clean-platform\/OS-Mac\"\n\t , \"clean-platform\/OS-Posix\"\n\t , \"clean-platform\/OS-Windows\"\n\t , \"clean-platform\/OS-Windows-32\"\n\t , \"clean-platform\/OS-Windows-64\"\n\t , \"iTasks-SDK\/Dependencies\/graph_copy\"\n\t , \"iTasks-SDK\/Dependencies\/clean-sapl\/src\"\n\t , \"iTasks-SDK\/Server\"\n\t , \"iTasks-SDK\/Tests\"\n\t , \"SoccerFun\/Game\"\n\t , \"SoccerFun\/Gui\"\n\t , \"SoccerFun\/StdLibExt\"\n\t , \"SoccerFun\/StdReferee\"\n\t , \"SoccerFun\/StdTeam\"\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"clean-platform\/OS-Independent\/Deprecated\"\n\t , \"iTasks-SDK\/Server\/lib\"\n\t , \"SoccerFun\/StdReferee\/RefereeCoach_\"\n\t , \"SoccerFun\/StdTeam\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (\\l -> findModules cli.exclude cli.root l \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putTypes predefTypes db\n\t# f = 'DB'.saveDb db f\n\t= fclose f w\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String)] 'DB'.TypeDB *DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib cache db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[x:c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t\t\t]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"{#Char}\" []) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[]}\n\n\/\/ Exclude Root Library Base module Library Module\nfindModules :: ![String] !String !String !String !*World -> *(![(String,String)], !*World)\nfindModules ex root lib base w\n| any (\\e -> indexOf e path <> -1) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s -> (lib, basedot +++ s % (0, size s - 5))) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (\\d -> findModules ex root lib (basedot +++ d)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any (\\e -> indexOf e (path +++ \"\/\" +++ s) <> -1) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String String String *DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib cache db w\n# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ \".dcl\"\n# (ok,f,w) = fopen filename FReadText w\n| not ok = abort (\"Couldn't open file \" +++ filename +++ \".\\n\")\n# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n cache = {cache & hash_table=ht}\n# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" False mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n cache = {cache & hash_table=ht}\n# (ok,w) = fclose f w\n| not ok = abort (\"Couldn't close file \" +++ filename +++ \".\\n\")\n# mod = pm.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putFunctions (pd_typespecs lib mod pm.mod_defs) db\n# db = 'DB'.putInstancess (pd_instances lib mod pm.mod_defs) db\n# db = 'DB'.putClasses (pd_classes lib mod pm.mod_defs) db\n# typedefs = pd_types lib mod pm.mod_defs\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib mod pm.mod_defs) db\n# db = 'DB'.putDerivationss (pd_derivations lib mod pm.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib mod pm.mod_defs) db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod pds\n\t\t= [( 'DB'.Location lib mod (toLine pos) id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= toPrio}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- pds]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id pds of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id pds\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):pds]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:pds] = findTypeSpec id pds\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, 'DB'.Location)])]\n\tpd_derivations lib mod pds\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, 'DB'.Location lib mod (toLine gc_pos) \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- pds, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod pds\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) id_name\n\t\t , 'DB'.ET ('T'.toType gen_type) {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars}\n\t\t ) \\\\ PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars} <- pds]\n\n\tpd_typespecs :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod pds\n\t\t= [( 'DB'.Location lib mod (toLine pos) id_name\n\t\t , 'DB'.ET ('T'.toType t) {zero & te_priority=toPrio p, te_representation=cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- pds]\n\n\tpd_instances :: String String [ParsedDefinition]\n\t\t-> [('DB'.Class, [('DB'.Type, 'DB'.Location)])]\n\tpd_instances lib mod pds\n\t\t= [( pi_ident.id_name\n\t\t , [('T'.toType t, 'DB'.Location lib mod (toLine pi_pos) \"\") \\\\ t <- pi_types]\n\t\t ) \\\\ PD_Instance {pim_pi={pi_ident,pi_types,pi_pos}} <- pds]\n\n\tpd_classes :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod pds\n\t# pds = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) pds\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} pds)\n\t\t-> let typespecs = pd_typespecs lib mod pds\n\t\tin ('DB'.Location lib mod (toLine class_pos) id_name, map 'T'.toTypeVar class_args,\n\t\t flatten $ map 'T'.toClassContext class_context,\n\t\t [(f,et) \\\\ ('DB'.Location _ _ _ f, et) <- typespecs])) pds\n\n\tpd_types :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod pds\n\t\t= [('DB'.Location lib mod (toLine ptd.td_pos) ('T'.td_name td), td)\n\t\t \\\\ PD_Type ptd <- pds, td <- ['T'.toTypeDef ptd]]\n\n\tconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tconstructor_functions ('DB'.Location lib mod line _, td)\n\t\t= [('DB'.Location lib mod line c, 'DB'.ET f {zero & te_isconstructor=True})\n\t\t \\\\ (c,f) <- 'T'.constructorsToFunctions td]\n\n\trecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\trecord_functions ('DB'.Location lib mod line _, td)\n\t\t= [('DB'.Location lib mod line f, 'DB'.ET t {zero & te_isrecordfield=True})\n\t\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\n\ttoPrio :: Priority -> Maybe 'DB'.TE_Priority\n\ttoPrio (Prio LeftAssoc i) = Just $ 'DB'.LeftAssoc i\n\ttoPrio (Prio RightAssoc i) = Just $ 'DB'.RightAssoc i\n\ttoPrio (Prio NoAssoc i) = Just $ 'DB'.NoAssoc i\n\ttoPrio _ = Nothing\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"77db5249c78539c719bd57ac8c667cf056f8b587","subject":"Fix incorrect module header error newline","message":"Fix incorrect module header error newline\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/compiler-patch\/parse.icl","new_file":"backend\/compiler-patch\/parse.icl","new_contents":"implementation module parse\n\nimport StdEnv\nimport scanner, syntax, hashtable, utilities, predef, containers, genericsupport\n\nParseOnly :== False\n\ntoLineAndColumn {fp_line, fp_col}\n\t=\t{lc_line = fp_line, lc_column = fp_col}\n\n\/*\n\nParser for Clean 2.0\n\nConventions:\n\n- Parsing funtions with a name of the form try.. can fail without generating an error.\n The parser will try an other alternative.\n- Parsing functions with a name of the form want.. should succeed. If these functions\n fail an error message is generated.\n- Functions with names containing the character '_' are local functions.\n- All functions should consume the tokens taken form the state or given as argument,\n or put these tokens back themselves.\n*\/\n\n::\t*ParseErrorAdmin = \n\t{\tpea_file\t:: !*File\n\t,\tpea_ok\t\t:: !Bool\n\t}\n\n:: *ParseState =\n\t{\tps_scanState\t\t:: !ScanState\n\t,\tps_error\t\t\t:: !*ParseErrorAdmin\n\t,\tps_flags\t\t\t:: !Int\n\t,\tps_hash_table\t\t:: !*HashTable\n\t}\n\nPS_SkippingMask :== 1\nPS_SupportGenericsMask :==2\nPS_DynamicTypeUsedMask :== 4\n\n\/*\nappScanState :: (ScanState -> ScanState) !ParseState -> ParseState\nappScanState f pState=:{ps_scanState}\n\t#\tps_scanState = f ps_scanState\n\t=\t{\tpState & ps_scanState = ps_scanState }\n*\/\nappScanState f pState:==appScanState pState\n\twhere\n\tappScanState pState=:{ps_scanState}\n\t\t#\tps_scanState = f ps_scanState\n\t\t=\t{\tpState & ps_scanState = ps_scanState }\n\n\/*\naccScanState :: (ScanState -> (.t,ScanState)) !ParseState -> (.t,ParseState)\naccScanState f pState=:{ps_scanState}\n\t#\t( x, ps_scanState) = f ps_scanState\n\t=\t( x, {pState & ps_scanState = ps_scanState })\n*\/\naccScanState f pState:== accScanState pState\n\twhere\n\t\taccScanState pState=:{ps_scanState}\n\t\t\t#\t( x, ps_scanState) = f ps_scanState\n\t\t\t=\t( x, {pState & ps_scanState = ps_scanState })\n\ninstance getFilename ParseState\nwhere\n\tgetFilename pState = accScanState getFilename pState\n\nmakeStringType\n\t#! string_ident = predefined_idents.[PD_StringType]\n\t=: TA (MakeNewTypeSymbIdent string_ident 0) []\n\nHeadLazy:==0\nHeadStrict:==1\nHeadUnboxed:==2\nHeadOverloaded:==3;\nHeadUnboxedAndTailStrict:==4;\n\nmakeListTypeSymbol :: Int Int -> TypeSymbIdent\nmakeListTypeSymbol head_strictness arity\n\t# pre_def_list_index=if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_ListType\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictListType\n\t\t\t\t\t\t\tPD_UnboxedListType)\n\t#! list_ident = predefined_idents.[pre_def_list_index]\n\t= MakeNewTypeSymbIdent list_ident arity\n\nmakeTailStrictListTypeSymbol :: Int Int -> TypeSymbIdent\nmakeTailStrictListTypeSymbol head_strictness arity\n\t# pre_def_list_index=if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_TailStrictListType\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictTailStrictListType\n\t\t\t\t\t\t\tPD_UnboxedTailStrictListType)\n\t#! list_ident = predefined_idents.[pre_def_list_index]\n\t= MakeNewTypeSymbIdent list_ident arity\n\nmakeLazyArraySymbol arity\n\t#! lazy_array_ident = predefined_idents.[PD_LazyArrayType]\n\t= MakeNewTypeSymbIdent lazy_array_ident arity\n\nmakeStrictArraySymbol arity\n\t#! strict_array_ident = predefined_idents.[PD_StrictArrayType]\n\t= MakeNewTypeSymbIdent strict_array_ident arity\n\nmakeUnboxedArraySymbol arity\n\t#! unboxed_array_ident = predefined_idents.[PD_UnboxedArrayType]\n\t= MakeNewTypeSymbIdent unboxed_array_ident arity\n\nmakeTupleTypeSymbol form_arity act_arity\n\t#! tuple_ident = predefined_idents.[GetTupleTypeIndex form_arity]\n\t= MakeNewTypeSymbIdent tuple_ident act_arity\n\t\nclass try a\t :: !Token !*ParseState -> (!Optional a, !*ParseState)\nclass want a :: !*ParseState -> (!a, !*ParseState)\n\nstringToQualifiedModuleIdent module_name ident_name ident_class pState :== (ident,parse_state)\n\twhere\n\t\t({boxed_ident=ident},parse_state) = stringToQualifiedModuleBoxedIdent module_name ident_name ident_class pState\n\nstringToQualifiedModuleBoxedIdent :: !String !String !IdentClass !*ParseState -> (!BoxedIdent, !*ParseState)\nstringToQualifiedModuleBoxedIdent module_name ident_name ident_class pState=:{ps_hash_table}\n\t# (ident, ps_hash_table) = putIdentInHashTable ident_name ident_class ps_hash_table\n\t# (module_ident, ps_hash_table) = putQualifiedIdentInHashTable module_name ident ident_class ps_hash_table\n\t= (module_ident, {pState & ps_hash_table = ps_hash_table})\n\nstringToIdent s i p :== (ident,parse_state)\n\twhere\n\t\t({boxed_ident=ident},parse_state) = stringToBoxedIdent s i p\n\nstringToBoxedIdent :: !String !IdentClass !*ParseState -> (!BoxedIdent, !*ParseState)\nstringToBoxedIdent ident ident_class pState=:{ps_hash_table}\n\t# (ident, ps_hash_table) = putIdentInHashTable ident ident_class ps_hash_table\n\t= (ident, { pState & ps_hash_table = ps_hash_table } )\n\ninternalIdent s p :== (ident,parse_state)\n\twhere\n\t\t({boxed_ident=ident},parse_state) = internalBoxedIdent s p\n\ninternalBoxedIdent :: !String !*ParseState -> (!BoxedIdent, !*ParseState)\ninternalBoxedIdent prefix pState\n\t# ({fp_line,fp_col},pState=:{ps_hash_table})\t= getPosition pState\n\t case_string\t\t\t\t\t\t\t\t\t= prefix +++ \";\" +++ toString fp_line +++ \";\" +++ toString fp_col\n\t (case_ident, ps_hash_table)\t\t\t\t\t= putIdentInHashTable case_string IC_Expression ps_hash_table\n\t= (case_ident, { pState & ps_hash_table = ps_hash_table } )\n\nerroneousIdent = { id_name = \"\", id_info = nilPtr }\n\n\/*\n\tSome general overloaded parsing routines\n*\/\n\nwantSequence :: !Token !ScanContext !*ParseState -> (!.[a],!*ParseState) | want a\nwantSequence separator scanContext pState\n\t# (first, pState) = want pState\n\t (token, pState) = nextToken scanContext pState\n\t| separator == token\n\t\t# (rest, pState) = wantSequence separator scanContext pState\n\t\t= ([first : rest], pState)\n\t\/\/ otherwise \/\/ separator <> token\n\t= ([first], tokenBack pState)\n\/*\noptionalSequence start_token separator scanContext pState\n\t# (token, pState) = nextToken scanContext pState\n\t| token == start_token\n\t\t= wantSequence separator scanContext pState\n\t\t= ([], tokenBack pState)\n*\/\nparseList try_fun pState :== parse_list pState \/\/ try_fun *\n\/\/parseList try_fun pState = parse_list pState\n\twhere\n\t\/\/\tparse_list :: !*ParseState -> (tree, *ParseState)\n\t\tparse_list pState\n\t\t\t# (succ, tree, pState) = try_fun pState\n\t\t\t| succ\n\t\t\t\t# (trees, pState) = parse_list pState\n\t\t\t\t= ([tree : trees], pState)\n\t\t\t= ([], pState)\n\n\/\/wantSepList msg sep_token scanContext try_fun pState = want_list msg pState\nwantSepList msg sep_token scanContext try_fun pState :== want_list msg pState \/\/ try_fun (sep_token tryfun)*\n\twhere\n\t\twant_list msg pState\n\t\t\t# (succ, tree, pState) = try_fun pState\n\t\t\t| succ\n\t\t\t \t# (token, pState) = nextToken scanContext pState\n\t\t\t \t| token == sep_token\n\t\t\t\t\t# (trees, pState) = optSepList sep_token scanContext try_fun pState\n\t\t\t\t\t= ([tree : trees], pState)\n\t\t\t\t\/\/ otherwise \/\/ token <> sep_token\n\t\t\t\t\t= ([tree], tokenBack pState)\n\t\t\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t\t\t= ([tree], parseError (\"wantList of \"+msg) (Yes token) msg pState)\n\n\/\/optSepList sep_token scanContext try_fun pState = want_list msg pState\noptSepList sep_token scanContext try_fun pState :== want_list pState \/\/ [ try_fun (sep_token tryfun)* ]\n\twhere\n\t\twant_list pState\n\t\t\t# (succ, tree, pState) = try_fun pState\n\t\t\t| succ\n\t\t\t \t# (token, pState) = nextToken scanContext pState\n\t\t\t \t| token == sep_token\n\t\t\t\t\t# (trees, pState) = want_list pState\n\t\t\t\t\t= ([tree : trees], pState)\n\t\t\t\t\/\/ otherwise \/\/ token <> sep_token\n\t\t\t\t\t= ([tree], tokenBack pState)\n\t\t\t= ([], pState)\n\n\/\/wantList msg try_fun pState = want_list msg pState\nwantList msg try_fun pState :== want_list msg pState \/\/ try_fun +\n\twhere\n\t\twant_list msg pState\n\t\t\t# (succ, tree, pState) = try_fun pState\n\t\t\t| succ\n\t\t\t\t# (trees, pState) = parseList try_fun pState\n\t\t\t\t= ([tree : trees], pState)\n\t\t\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t\t\t= ([tree], parseError (\"wantList of \"+msg) (Yes token) msg pState)\n\noptionalPriority :: !Bool !Token !ParseState -> (Priority, !ParseState)\noptionalPriority isinfix (PriorityToken prio) pState\n\t= (prio, pState)\noptionalPriority isinfix token pState\n\t| isinfix\n\t\t= (DefaultPriority, tokenBack pState)\n\t\t= (NoPrio, tokenBack pState)\n\n\/*\n\tModules\n*\/\n\n::\tParseContext\t\t\t:== Int\n\ncICLContext\t\t\t\t\t:== 1\ncGlobalContext\t\t\t\t:== 2\ncDCLContext\t\t\t\t\t:== 0\ncLocalContext\t\t\t\t:== 1\nClassDefsContext\t\t\t:== 4\nInstanceDefsContext\t\t\t:== 8\nGlobalOrClassDefsContext\t:== 6 \/\/ cGlobalContext bitor ClassDefsContext\nClassOrInstanceDefsContext\t:== 12 \/\/ ClassDefsContext bitor InstanceDefsContext\n\/*\n\tA cClassOrInstanceDefsContext is a further restriction on a\n\tlocal context, because no local node defs are allowed\n\tThis context stuff is getting far too complicated.\n\tPossible solution: accept everything in the parser and\n\tdiscriminate in postparse, depending on the context.\n*\/\n\nSetGlobalContext iclmodule\n\t| iclmodule\n\t\t= cICLContext bitor cGlobalContext\n\t\t= cDCLContext bitor cGlobalContext\n\nSetLocalContext\t\t\tparseContext :== parseContext bitand (bitnot cGlobalContext)\nSetClassDefsContext\t\tparseContext :== SetLocalContext (parseContext bitor ClassDefsContext)\nSetInstanceDefsContext\tparseContext :== SetLocalContext (parseContext bitor InstanceDefsContext)\n\nisLocalContext\tparseContext\t:== parseContext bitand cGlobalContext == 0\nisGlobalContext\tparseContext\t:== parseContext bitand cGlobalContext <> 0 \/\/ not (isLocalContext parseContext)\n\nisDclContext\tparseContext\t:== parseContext bitand cICLContext == 0\nisIclContext\tparseContext\t:== parseContext bitand cICLContext <> 0\t\/\/ not (isDclContext parseContext)\n\nisNotClassOrInstanceDefsContext parseContext\t\t:== parseContext bitand ClassOrInstanceDefsContext == 0\nisGlobalOrClassDefsContext parseContext\t\t\t\t:== parseContext bitand GlobalOrClassDefsContext <> 0\nisInstanceDefsContext parseContext\t\t\t\t\t:== parseContext bitand InstanceDefsContext <> 0\n\ncWantIclFile :== True\ncWantDclFile :== False\n\nwantModule :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> (!Bool,!Bool,!ParsedModule, !*HashTable, !*File, !*Files)\nwantModule file modification_time iclmodule file_id=:{id_name} import_file_position support_generics hash_table error files\n\t# scanState = openScanner file id_name file_name_extension\n\t# hash_table = set_hte_mark (if iclmodule 1 0) hash_table\n\t hash_table = remove_qualified_idents_from_hash_table hash_table\n\t# (ok,dynamic_type_used,mod,hash_table,file,files) = initModule file_name modification_time scanState hash_table error files\n\t hash_table=set_hte_mark 0 hash_table\n\t= (ok,dynamic_type_used,mod,hash_table,file,files)\nwhere\n\tfile_name = id_name +++ file_name_extension\n\tfile_name_extension = if iclmodule \".icl\" \".dcl\"\n\n\tinitModule :: String String ScanState !*HashTable !*File *Files\n\t\t\t\t-> (!Bool,!Bool,!ParsedModule,!*HashTable,!*File,!*Files)\n\tinitModule file_name modification_time scanState hash_table error files\n\t\t# (succ, mod_type, mod_name, scanState) = try_module_header iclmodule scanState\n\t\t| succ\n\t\t\t# pState\t\t\t\t=\t{ ps_scanState = scanState\n\t\t\t\t\t\t\t\t\t\t, ps_error = { pea_file = error, pea_ok = True }\n\t\t\t\t\t\t\t\t\t\t, ps_flags = if support_generics PS_SupportGenericsMask 0\n\t\t\t\t\t\t\t\t\t\t, ps_hash_table = hash_table\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t pState\t\t\t\t= verify_name mod_name id_name file_name pState\n\t\t \t (mod_ident, pState)\t= stringToIdent mod_name (IC_Module NoQualifiedIdents) pState\n\t\t \t pState\t\t\t\t= check_layout_rule pState\n\t\t \t (defs, pState)\t\t= want_definitions (SetGlobalContext iclmodule) pState\n\t\t\t {ps_scanState,ps_hash_table,ps_error,ps_flags}\n\t\t\t \t\t\t\t\t\t= pState\n\t\t\t defs = if (ParseOnly && id_name <> \"StdOverloaded\" && id_name <> \"StdArray\" && id_name <> \"StdEnum\" && id_name <> \"StdBool\" && id_name <> \"StdDynamics\" && id_name <> \"StdGeneric\")\n\t\t\t\t\t\t[PD_Import imports \\\\ PD_Import imports <- defs]\n\t\t\t\t\t\tdefs\n\t\t\t mod\t= { mod_ident = mod_ident, mod_modification_time = modification_time, mod_type = mod_type, mod_imports = [], mod_imported_objects = [], mod_foreign_exports=[],mod_defs = defs }\n\t\t\t files = closeScanner ps_scanState files\n\t\t\t= ( ps_error.pea_ok, ps_flags bitand PS_DynamicTypeUsedMask<>0, mod, ps_hash_table, ps_error.pea_file, files)\n\t\t\/\/ otherwise \/\/ ~ succ\n\t\t# ({fp_line}, scanState) = getPosition scanState\n\t\t mod = { mod_ident = file_id, mod_modification_time = modification_time, mod_type = mod_type, mod_imports = [], mod_imported_objects = [],mod_foreign_exports=[],mod_defs = [] }\n\t\t= (False, False, mod, hash_table, error <<< \"Error [\" <<< file_name <<< ',' <<< fp_line <<< \"]: incorrect module header\\n\",\n\t\t\tcloseScanner scanState files)\n\n\ttry_module_header :: !Bool !ScanState -> (!Bool,!ModuleKind,!String,!ScanState)\n\ttry_module_header is_icl_mod scanState\n\t\t# (token, scanState) = nextToken GeneralContext scanState\n\t\t| is_icl_mod\n\t\t\t| token == ModuleToken\n\t\t\t\t# (token, scanState) = nextToken GeneralContext scanState\n\t\t\t\t= try_module_name token MK_Main scanState\n\t\t\t| token == ImpModuleToken \n\t\t\t\t= try_module_token MK_Module scanState\n\t\t\t| token == SysModuleToken\n\t\t\t\t= try_module_token MK_System scanState\n\t\t\t\t= (False, MK_None, \"\", tokenBack scanState)\n\t\t| token == DefModuleToken\n\t\t \t= try_module_token MK_Module scanState\n\t\t| token == SysModuleToken\n\t\t \t= try_module_token MK_System scanState\n\t\t\t= (False, MK_None, \"\", tokenBack scanState)\n\n\ttry_module_token :: !ModuleKind !ScanState -> (!Bool,!ModuleKind,!String,!ScanState)\n\ttry_module_token mod_type scanState\n\t\t# (token, scanState) = nextToken GeneralContext scanState\n\t\t| token == ModuleToken\n\t\t\t# (token, scanState) = nextToken ModuleNameContext scanState\n \t\t\t= try_module_name token mod_type scanState\n\t\t\t= (False, mod_type, \"\", tokenBack scanState)\n\n\ttry_module_name (IdentToken name) mod_type scanState\n\t\t= (True, mod_type, name, scanState)\n\ttry_module_name (UnderscoreIdentToken name) mod_type scanState\n\t\t= (True, mod_type, name, setUseUnderscoreIdents True scanState)\n\ttry_module_name token mod_type scanState\n\t\t= (False, mod_type, \"\", tokenBack scanState)\n\t\n\tverify_name name id_name file_name pState\n\t\t| name == id_name\n\t \t\t= pState\n\t\t\t# ({fp_line}, pState=:{ps_error={pea_file}}) = getPosition pState\n \t\t\t pea_file = pea_file <<< \"Error [\" <<< file_name <<< ',' <<< fp_line <<< \"]: module name \\\"\" <<< name \n\t \t\t\t\t\t\t<<< \"\\\" does not match file name: \\\"\" <<< file_name <<<\"\\\"\\n\"\n\t\t\t= { pState & ps_error = { pea_file = pea_file, pea_ok = False }}\n\n\tcheck_layout_rule pState\n\t\t# (token, pState)\t= nextToken GeneralContext pState\n\t\t use_layout\t\t= token <> SemicolonToken && token <> EndOfFileToken \/\/ '&& token <> EndOfFileToken' to handle end groups of empty modules\n\t\t| use_layout\t\t= appScanState (setUseLayout use_layout) (tokenBack pState)\n\t\t\t\t\t\t\t= appScanState (setUseLayout use_layout) pState\n\n\twant_definitions :: !ParseContext !ParseState -> (![ParsedDefinition], !ParseState)\n\twant_definitions parseContext pState\n\t\t= want_acc_definitions [] pState\n\twhere\n\t\twant_acc_definitions :: ![ParsedDefinition] !ParseState -> (![ParsedDefinition], !ParseState)\n\t\twant_acc_definitions acc pState\n\t\t\t# (defs, pState)\t= wantDefinitions parseContext pState\n\t\t\t acc\t\t\t\t= acc ++ defs\n\t\t\t pState\t\t\t= wantEndModule pState\n\t\t\t (token, pState)\t= nextToken FunctionContext pState\n\t\t\t| token == EndOfFileToken\n\t\t\t\t= (acc, pState)\n\t\t\t\t# pState\t\t= parseError \"want definitions\" (Yes token) \"End of file\" pState\n\t\t\t\t pState\t\t= wantEndOfDefinition \"definitions\" pState\n\t\t\t\t= want_acc_definitions acc pState\n\nmoduleCouldNotBeImportedError :: !Bool !Ident !Position !*File -> *File\nmoduleCouldNotBeImportedError iclmodule file_id=:{id_name} import_file_position error\n\t# file_name_extension = if iclmodule \".icl\" \".dcl\"\n\t file_name = id_name +++ file_name_extension\n\t= error <<< \"Error \" <<< import_file_position <<< \": \" <<< file_name <<< \" could not be imported\\n\"\n\n\/*\n\t[Definition] on local and global level\n*\/\n\nwantDefinitions :: !ParseContext !ParseState -> (![ParsedDefinition], !ParseState)\nwantDefinitions parseContext pState\n\t= parseList (tryDefinition parseContext) pState\n\ncHasPriority \t:== True\ncHasNoPriority\t:== False\n\ntryDefinition :: !ParseContext !ParseState -> (!Bool, ParsedDefinition, !ParseState)\ntryDefinition parseContext pState\n\t# (token, pState)\t\t\t= nextToken GeneralContext pState\n\t (fname, linenr, pState)\t= getFileAndLineNr pState\n\t= try_definition parseContext token (LinePos fname linenr) pState\nwhere\n\ttry_definition :: !ParseContext !Token !Position !ParseState -> (!Bool, ParsedDefinition, !ParseState)\n\ttry_definition parseContext DoubleColonToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(3)\",parseError \"definition\" No \"type definitions only at the global level\" (tokenBack pState))\n\t\t\t# (def, pState) = wantTypeDef parseContext pos pState\n\t\t\t= (True, def, pState)\n\ttry_definition parseContext (IdentToken name) pos pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tGenericOpenToken\n\t\t\t\t\/\/ generic function\n\t\t\t\t-> wantGenericFunctionDefinition name pos pState\n\t\t\t_ \/\/ normal function\n\t\t\t\t# pState = tokenBack pState\n\t\t\t\t# (lhs, pState) = want_lhs_of_def (IdentToken name) pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (def, pState) = want_rhs_of_def parseContext lhs token (determine_position lhs pos) pState\n\t\t\t\t-> (True, def, pState)\n\ttry_definition _ ImportToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(3)\",parseError \"definition\" No \"imports only at the global level\" pState)\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == CodeToken && isIclContext parseContext\n\t\t\t# (importedObjects, pState) = wantCodeImports pState\n\t\t\t= (True, PD_ImportedObjects importedObjects, pState)\n\t\t\t# pState = tokenBack pState\n\t\t\t# (imports, pState) = wantImports pState\n\t \t\t= (True, PD_Import imports, pState)\n\ttry_definition _ FromToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(3)\",parseError \"definition\" No \"imports only at the global level\" pState)\n\t\t\t# (imp, pState) = wantFromImports pState\n\t \t\t= (True, PD_Import [imp], pState)\n\ttry_definition parseContext ClassToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(2)\",parseError \"definition\" No \"class definitions are only at the global level\" pState)\n\t \t\t# (classdef, pState) = wantClassDefinition parseContext pos pState\n\t \t\t= (True, classdef, pState)\n\ttry_definition parseContext GenericToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(2)\",parseError \"definition\" No \"generic definitions are only at the global level\" pState)\n\t \t\t# (gendef, pState) = wantGenericDefinition parseContext pos pState\n\t \t\t= (True, gendef, pState)\n\ttry_definition parseContext DeriveToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(2)\",parseError \"definition\" No \"derive declarations are only at the global level\" pState) \t\t\n\t \t\t# (gendef, pState) = wantDeriveDefinition parseContext pos pState\n\t \t\t= (True, gendef, pState)\n\ttry_definition parseContext InstanceToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(2)\",parseError \"definition\" No \"instance declarations are only at the global level\" pState)\n\t \t\t# (instdef, pState) = wantInstanceDeclaration parseContext pos pState\n\t \t\t= (True, instdef, pState)\n\ttry_definition parseContext ForeignToken pos pState\n\t\t| not (isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def\",parseErrorSimple \"definition\" \"foreign export definitions are only allowed at the global level\" pState)\n\t\t| isDclContext parseContext\n\t\t\t= (False,abort \"no def\",parseErrorSimple \"definition\" \"foreign export definitions are only allowed in implementation modules\" pState)\n\t\t\t= wantForeignExportDefinition pState\n\ttry_definition parseContext token pos pState\n\t\t| isLhsStartToken token\n\t\t\t# (lhs, pState) = want_lhs_of_def token pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t (def, pState) = want_rhs_of_def parseContext lhs token (determine_position lhs pos) pState\n\t\t\t= (True, def, pState)\n\t\t= (False, abort \"no def(1)\", tokenBack pState)\n\n\tdetermine_position (Yes (name, _), _)\t(LinePos f l) = FunPos f l name.id_name\n\tdetermine_position lhs \t\tpos = pos\n\n\twant_lhs_of_def :: !Token !ParseState -> (!(Optional (Ident, Bool), ![ParsedExpr]), !ParseState)\n\twant_lhs_of_def token pState\n\t\t# (succ, fname, is_infix, pState) = try_function_symbol token pState\n\t\t| succ\n\t\t\t# (args, pState) = parseList trySimplePattern pState\n\t\t\t= ((Yes (fname, is_infix), args), pState)\n\t\t\t# (_, exp, pState) = trySimplePattern pState\n\t\t\t= ((No, [exp]), pState)\n\twhere\n\t\ttry_function_symbol :: !Token !ParseState -> (!Bool, Ident, !Bool, !ParseState) \/\/ (Success, Ident, Infix, ParseState)\n\t\ttry_function_symbol (IdentToken name) pState\n\t\t\t# (id, pState) = stringToIdent name IC_Expression pState\n\t\t\t= (True, id, False, pState)\n\t\ttry_function_symbol OpenToken pState\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t= case token of\n\t\t\t\tIdentToken name\n\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t| CloseToken == token\n\t\t\t\t\t\t# (id, pState) = stringToIdent name IC_Expression pState\n\t\t\t\t\t\t-> (True, id, True, pState)\n\t\t\t\t\t\t-> (False, abort \"no name\", False, tokenBack (tokenBack (tokenBack pState)))\n\t\t\t\t_\n\t\t\t\t\t-> (False, abort \"no name\", False, tokenBack (tokenBack pState))\n\t\ttry_function_symbol token pState\n\t\t\t= (False, abort \"name\", False, tokenBack pState)\n\n\twant_rhs_of_def :: !ParseContext !(Optional (Ident, Bool), [ParsedExpr]) !Token !Position !ParseState -> (ParsedDefinition, !ParseState)\n\twant_rhs_of_def parseContext (opt_name, []) DoubleColonToken pos pState\n\t\t# (name, is_infix, pState) = check_name_and_fixity opt_name cHasNoPriority pState\n\t\t (tspec, pState) = wantSymbolType pState\n\t\t| isDclContext parseContext\n\t\t\t# (specials, pState) = optionalFunSpecials pState\n\t\t\t= (PD_TypeSpec pos name (if is_infix DefaultPriority NoPrio) (Yes tspec) specials, wantEndOfDefinition \"type definition\" pState)\n\t\t\t= (PD_TypeSpec pos name (if is_infix DefaultPriority NoPrio) (Yes tspec) FSP_None, wantEndOfDefinition \"type definition\" pState)\n\twant_rhs_of_def parseContext (opt_name, args) (PriorityToken prio) pos pState\n\t\t# (name, _, pState) = check_name_and_fixity opt_name cHasPriority pState\n\t\t (token, pState) = nextToken TypeContext pState\n\t\t| token == DoubleColonToken\n\t\t \t# (tspec, pState) = wantSymbolType pState\n\t\t\t| isDclContext parseContext\n\t\t\t\t# (specials, pState) = optionalFunSpecials pState\n\t\t\t\t= (PD_TypeSpec pos name prio (Yes tspec) specials, wantEndOfDefinition \"type definition\" pState)\n\t\t\t\t= (PD_TypeSpec pos name prio (Yes tspec) FSP_None, wantEndOfDefinition \"type definition\" pState)\n\t\t\t= (PD_TypeSpec pos name prio No FSP_None, wantEndOfDefinition \"type definition\" (tokenBack pState))\n\twant_rhs_of_def parseContext (No, args) token pos pState\n\t\t# pState\t\t\t= want_node_def_token pState token\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t localsExpected\t= ~ ss_useLayout\n\t\t (rhs, _, pState)\t\t= wantRhs localsExpected (ruleDefiningRhsSymbol parseContext (isNotEmpty args)) (tokenBack pState)\n\t\t| isLocalContext parseContext\n\t\t\t| isNotClassOrInstanceDefsContext parseContext\n \t\t\t\t= (PD_NodeDef pos (combine_args args) rhs, pState)\n\t \t\t\t= (PD_NodeDef pos (combine_args args) rhs, parseError \"RHS\" No \"\" pState)\n\t\t\t= (PD_NodeDef pos (combine_args args) rhs, parseError \"RHS\" No \"\" pState)\n\twhere\t\t\n\t\twant_node_def_token s EqualToken\t\t= s\n\t\twant_node_def_token s token\t\t\t\t= parseError \"RHS\" (Yes token) \"defines token (=)\" s\n\n\t\tcombine_args [arg]\t= arg\n\t\tcombine_args args\t= PE_List args\n\twant_rhs_of_def parseContext (Yes (name, False), []) definingToken pos pState\n\t\t# code_allowed = definingToken == EqualToken\n\t\t| isIclContext parseContext && isLocalContext parseContext && (definingToken == EqualToken || (definingToken == DefinesColonToken && isGlobalContext parseContext)) &&\n\t\t\/* PK isLowerCaseName name.id_name && *\/ isNotClassOrInstanceDefsContext parseContext\n\t\t \t# (token, pState) = nextToken FunctionContext pState\n\t\t\t| code_allowed && token == CodeToken\n\t\t\t\t# (rhs, pState) = wantCodeRhs pState\n\t\t\t\t= (PD_Function pos name False [] rhs (FK_Function cNameNotLocationDependent), pState)\n\t\t\t# pState = tokenBack pState\n\t\t\t# (rhs, _, pState) = wantRhs False (RhsDefiningSymbolExact definingToken) (tokenBack pState)\n\t\t\t| token == EqualToken\n\t\t\t\t= (PD_Function pos name False [] rhs FK_NodeDefOrFunction, pState)\n\t\t\t\/\/ otherwise \/\/ token == DefinesColonToken\n \t\t\t\t| isGlobalContext parseContext\n\t\t\t\t\t= (PD_Function pos name False [] rhs FK_Caf, pState)\n\t\t\t\t\/\/ otherwise\n\t\t\t\t\t= (PD_NodeDef pos (PE_Ident name) rhs, pState)\n\twant_rhs_of_def parseContext (Yes (name, is_infix), args) token pos pState\n\t\t# code_allowed = token == EqualToken || token == DoubleArrowToken\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| isIclContext parseContext && token == CodeToken\n\t\t\t# (rhs, pState) = wantCodeRhs pState\n\t\t\t| code_allowed\n\t\t\t\t= (PD_Function pos name is_infix args rhs (FK_Function cNameNotLocationDependent), pState)\n\t\t\t\/\/ otherwise \/\/ ~ code_allowed\n\t\t\t\t= (PD_Function pos name is_infix args rhs (FK_Function cNameNotLocationDependent), parseError \"rhs of def\" No \"no code\" pState)\n\t\t# pState = tokenBack (tokenBack pState)\n\t\t (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t has_args = isNotEmpty args\n\t\t localsExpected = has_args || isGlobalContext parseContext || ~ ss_useLayout\n\t\t (rhs, defining_symbol, pState)\n\t\t \t\t= wantRhs localsExpected (ruleDefiningRhsSymbol parseContext has_args) pState\n\t\t fun_kind = definingSymbolToFunKind defining_symbol\n\t\t= case fun_kind of\n\t\t\tFK_Function _ | isDclContext parseContext\n\t\t\t\t->\t(PD_Function pos name is_infix args rhs fun_kind, parseError \"RHS\" No \"\" pState)\n\t\t\tFK_Caf | isNotEmpty args\n\t\t\t\t->\t(PD_Function pos name is_infix [] rhs fun_kind, parseError \"CAF\" No \"No arguments for a CAF\" pState)\n\t\t\t_\t->\t(PD_Function pos name is_infix args rhs fun_kind, pState)\n\n\twantGenericFunctionDefinition name pos pState\n\t\t\/\/# (type, pState) = wantType pState\n\t\t# (ok, {at_type=type}, pState) = trySimpleType TA_None pState\n\t\t# (ident, pState) = stringToIdent name (IC_GenericCase type) pState\n\t\t# (generic_ident, pState) = stringToIdent name IC_Generic pState\t\n\t\t# (type_cons, generic_fun_ident, pState) = get_type_cons type pState\n\t\t\twith\n\t\t\t\tget_type_cons (TA type_symb []) pState\n\t\t\t\t\t= make_generic_fun_ident (TypeConsSymb type_symb) pState\n\t\t\t\tget_type_cons (TA type_symb _) pState\n\t\t\t\t\t# pState = parseError \"generic type, no constructor arguments allowed\" No \" |}\" pState\n\t\t\t\t\t= (abort_no_TypeCons, abort_no_TypeCons, pState)\n\t\t\t\tget_type_cons (TB tb) pState\n\t\t\t\t\t= make_generic_fun_ident (TypeConsBasic tb) pState\n\t\t\t\tget_type_cons TArrow pState\n\t\t\t\t\t= make_generic_fun_ident TypeConsArrow pState\n\t\t\t\tget_type_cons (TV tv) pState\n\t\t\t\t\t= make_generic_fun_ident (TypeConsVar tv) pState\n\t\t\t\tget_type_cons _ pState \n\t\t\t\t\t# pState = parseError \"generic type\" No \" |}\" pState\n\t\t\t\t\t= (abort_no_TypeCons, abort_no_TypeCons, pState)\n\t\t\t\t\n\t\t\t\tmake_generic_fun_ident type_cons pState\n\t\t\t\t\t# generic_fun_ident = genericIdentToFunIdent name type_cons\n\t\t\t\t\t (generic_fun_ident,pState) = stringToIdent generic_fun_ident.id_name IC_Expression pState\n\t\t\t\t\t= (type_cons, generic_fun_ident, pState)\n\n\t\t# (token, pState) = nextToken GenericContext pState\n\t\t# (geninfo_arg, gcf_generic_info, pState) = case token of\n\t\t\tGenericOfToken\n\t\t\t\t# (ok, geninfo_arg, pState) = trySimplePattern pState\n\t\t\t\t# pState = wantToken FunctionContext \"type argument\" GenericCloseToken pState\n\t\t\t\t| ok \n\t\t\t\t\t-> case type_cons of\n\t\t\t\t\t\tTypeConsSymb {type_ident=type_ident=:{id_name}}\n\t\t\t\t\t\t\t| id_name==\"OBJECT\"\n\t\t\t\t\t\t\t\t# (generic_constructor_type_ident, pState) = stringToIdent id_name IC_Type pState\n\t\t\t\t\t\t\t\t| type_ident==generic_constructor_type_ident\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, generic_info_of_OBJECT_geninfo_arg geninfo_arg, pState)\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, 0, pState)\n\t\t\t\t\t\t\t| id_name==\"CONS\"\n\t\t\t\t\t\t\t\t# (generic_constructor_type_ident, pState) = stringToIdent id_name IC_Type pState\n\t\t\t\t\t\t\t\t| type_ident==generic_constructor_type_ident\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, generic_info_of_CONS_geninfo_arg geninfo_arg, pState)\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, 0, pState)\n\t\t\t\t\t\t\t| id_name==\"RECORD\"\n\t\t\t\t\t\t\t\t# (generic_constructor_type_ident, pState) = stringToIdent id_name IC_Type pState\n\t\t\t\t\t\t\t\t| type_ident==generic_constructor_type_ident\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, generic_info_of_RECORD_geninfo_arg geninfo_arg, pState)\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, 0, pState)\n\t\t\t\t\t\t\t| id_name==\"FIELD\"\n\t\t\t\t\t\t\t\t# (generic_constructor_type_ident, pState) = stringToIdent id_name IC_Type pState\n\t\t\t\t\t\t\t\t| type_ident==generic_constructor_type_ident\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, generic_info_of_FIELD_geninfo_arg geninfo_arg, pState)\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, 0, pState)\n\t\t\t\t\t\t_\n\t\t\t\t\t\t\t-> (geninfo_arg, 0, pState)\n\t\t\t\t| otherwise\n\t\t\t\t\t# pState = parseError \"generic case\" No \"simple lhs expression\" pState\n\t\t\t\t\t-> (PE_Empty, 0, pState)\n\n\t\t\tGenericCloseToken\n\t\t\t\t-> (PE_WildCard, 0, pState)\n\t\t\t_ \t\n\t\t\t\t# pState = parseError \"generic type\" (Yes token) \"of or |}\" pState\n\t\t\t\t-> (PE_WildCard, 0, pState)\n\n\t\t\/\/# pState = wantToken FunctionContext \"type argument\" GenericCloseToken pState\n\t\t# (args, pState) = parseList trySimplePattern pState\n\t \t# has_args = isNotEmpty args || gcf_generic_info<>0\n\t\t# args = [geninfo_arg : args]\n\n\t \t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t # localsExpected = has_args || isGlobalContext parseContext || ~ ss_useLayout\n\t # (rhs, _, pState) = wantRhs localsExpected (ruleDefiningRhsSymbol parseContext has_args) pState\n\n\t\t# generic_case =\n\t\t\t{ gc_pos = pos\n\t\t\t, gc_type = type\n\t\t\t, gc_type_cons = type_cons\n\t\t\t, gc_gcf = GCF ident {\n\t\t\t\t\t\tgcf_gident = generic_ident,\n\t\t\t\t\t\tgcf_generic = {gi_module=NoIndex,gi_index=NoIndex},\n\t\t\t\t\t\tgcf_arity = length args,\n\t\t\t\t\t\tgcf_generic_info = gcf_generic_info,\n\t\t\t\t\t\tgcf_body = GCB_ParsedBody args rhs,\n\t\t\t\t\t\tgcf_kind = KindError,\n\t\t\t\t\t\tgcf_generic_instance_deps = AllGenericInstanceDependencies }\n\t\t\t}\n\t\t= (True, PD_GenericCase generic_case generic_fun_ident, pState)\n\n\tabort_no_TypeCons => abort \"no TypeCons\"\n\n\twantForeignExportDefinition pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t# (file_name,line_nr,pState) = getFileAndLineNr pState\n\t\t= case token of\n\t\t\tIdentToken \"export\"\n\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t-> case token of\n\t\t\t\t\tIdentToken function_name\n\t\t\t\t\t\t| function_name==\"ccall\"\n\t\t\t\t\t\t\t# (token2, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t-> case token2 of\n\t\t\t\t\t\t\t\tIdentToken function_name\n\t\t\t\t\t\t\t\t\t-> accept_foreign_export function_name line_nr False pState\n\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t-> accept_foreign_export function_name line_nr False (tokenBack pState)\n\t\t\t\t\t\t| function_name==\"stdcall\"\n\t\t\t\t\t\t\t# (token2, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t-> case token2 of \n\t\t\t\t\t\t\t\tIdentToken function_name\n\t\t\t\t\t\t\t\t\t-> accept_foreign_export function_name line_nr True pState\n\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t-> accept_foreign_export function_name line_nr False (tokenBack pState)\n\t\t\t\t\t\t\t-> accept_foreign_export function_name line_nr False pState\n\t\t\t\t\t_\n\t\t\t\t\t\t-> foreign_export_error \"function name\" pState\n\t\t\t\twhere\n\t\t\t\t\taccept_foreign_export function_name line_nr stdcall pState\n\t\t\t\t\t\t# pState = wantEndOfDefinition \"foreign export\" pState\n\t\t\t\t\t\t# (ident,pState) = stringToIdent function_name IC_Expression pState\n\t\t\t\t\t\t= (True,PD_ForeignExport ident file_name line_nr stdcall,pState)\n\t\t\t_\n\t\t\t\t-> foreign_export_error \"export\" pState\n\t\twhere\n\t\t\tforeign_export_error s pState\n\t\t\t\t= (True,PD_Erroneous,tokenBack (parseError \"foreign export\" No s pState))\n\ngeneric_info_of_RECORD_geninfo_arg (PE_Record PE_Empty NoRecordName field_assignments)\n\t= mark_GenericRecordDescriptor_fields field_assignments 0\n where\n\tmark_GenericRecordDescriptor_fields :: [FieldAssignment] !Int -> Int \n\tmark_GenericRecordDescriptor_fields [{bind_dst=FieldName {id_name}}:field_assignments] generic_info\n\t\t# field_number=field_n_of_GenericRecordDescriptor id_name\n\t\t| field_number>=0 && generic_info bitand (1< Int \n\tmark_GenericTypeDefDescriptor_fields [{bind_dst=FieldName {id_name}}:field_assignments] generic_info\n\t\t# field_number=field_n_of_GenericTypeDefDescriptor id_name\n\t\t| field_number>=0 && generic_info bitand (1< Int\n\tmark_GenericConsDescriptor_fields [{bind_dst=FieldName {id_name}}:field_assignments] generic_info\n\t\t# field_number=field_n_of_GenericConsDescriptor id_name\n\t\t| field_number>=0 && generic_info bitand (1< Int\n\tmark_GenericFieldDescriptor_fields [{bind_dst=FieldName {id_name}}:field_assignments] generic_info\n\t\t# field_number=field_n_of_GenericFieldDescriptor id_name\n\t\t| field_number>=0 && generic_info bitand (1< (![ParsedDefinition], !ParseState)\nwant_instance_type_definitions instance_type pState\n\t= parseList want_instance_type_definition pState\nwhere\n\twant_instance_type_definition :: !ParseState -> (!Bool, ParsedDefinition, !ParseState)\n\twant_instance_type_definition pState\n\t\t# (token, pState)\t\t\t= nextToken GeneralContext pState\n\t\t (fname, linenr, pState)\t= getFileAndLineNr pState\n\t\t pos = LinePos fname linenr\n\t\t| isLhsStartToken token\n\t\t\t# (lhs, pState) = want_lhs_of_def token pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (def, pState) = want_rhs_of_instance_member_def lhs token (determine_position lhs pos) pState\n\t\t\t= (True, def, pState)\n\t\t= (False, abort \"no def(1)\", tokenBack pState)\n\twhere\n\t\tdetermine_position (Yes (name, _))\t(LinePos f l) = FunPos f l name.id_name\n\t\tdetermine_position lhs \tpos = pos\n\n\twant_lhs_of_def :: !Token !ParseState -> (!Optional (Ident, Bool), !ParseState)\n\twant_lhs_of_def token pState\n\t\t# (succ, fname, is_infix, pState) = try_function_symbol token pState\n\t\t| succ\n\t\t\t# (function_ident, pState) = stringToIdent fname (IC_InstanceMember instance_type) pState\n\t\t\t= (Yes (function_ident, is_infix), pState)\n\t\t\t= (No, pState)\n\twhere\n\t\ttry_function_symbol :: !Token !ParseState -> (!Bool, {#Char}, !Bool, !ParseState)\n\t\ttry_function_symbol (IdentToken name) pState\n\t\t\t= (True, name, False, pState)\n\t\ttry_function_symbol OpenToken pState\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t= case token of\n\t\t\t\tIdentToken name\n\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t| CloseToken == token\n\t\t\t\t\t\t-> (True, name, True, pState)\n\t\t\t\t\t\t-> (False, abort \"no name\", False, tokenBack (tokenBack (tokenBack pState)))\n\t\t\t\t_\n\t\t\t\t\t-> (False, abort \"no name\", False, tokenBack (tokenBack pState))\n\t\ttry_function_symbol token pState\n\t\t\t= (False, abort \"name\", False, tokenBack pState)\n\n\tcheck_name No pState\n\t\t= (erroneousIdent, NoPrio, parseError \"Definition\" No \"identifier\" pState)\n\tcheck_name (Yes (name,False)) pState\n\t\t= (name, NoPrio, pState)\n\tcheck_name (Yes (name,is_infix)) pState\n\/\/\t\t= (name, DefaultPriority, pState)\n\t\t= (name, Prio NoAssoc 9, pState)\n\n\twant_rhs_of_instance_member_def :: !(Optional (Ident, Bool)) !Token !Position !ParseState -> (ParsedDefinition, !ParseState)\n\twant_rhs_of_instance_member_def opt_name DoubleColonToken pos pState\n\t\t# (name, priority, pState) = check_name opt_name pState\n\t\t (tspec, pState) = wantSymbolType pState\n\t\t= (PD_TypeSpec pos name priority (Yes tspec) FSP_None, wantEndOfDefinition \"type definition\" pState)\n\twant_rhs_of_instance_member_def opt_name (PriorityToken prio) pos pState\n\t\t# (name,_,pState) = check_name_and_fixity opt_name cHasPriority pState\n\t\t (token, pState) = nextToken TypeContext pState\n\t\t| token == DoubleColonToken\n\t\t \t# (tspec, pState) = wantSymbolType pState\n\t\t\t= (PD_TypeSpec pos name prio (Yes tspec) FSP_None, wantEndOfDefinition \"type definition\" pState)\n\t\t\t# pState = parseError \"type definition\" (Yes token) \"::\" pState\n\t\t\t= (PD_TypeSpec pos name prio No FSP_None, wantEndOfDefinition \"type defenition\" pState)\n\twant_rhs_of_instance_member_def opt_name token pos pState\n\t\t# pState = parseError \"type definition\" (Yes token) \"::\" pState\n\t\t= (PD_Erroneous, wantEndOfDefinition \"type defenition\" pState)\n\ncheck_name_and_fixity No hasprio pState\n\t= (erroneousIdent, False, parseError \"Definition\" No \"identifier\" pState)\ncheck_name_and_fixity (Yes (name,is_infix)) hasprio pState\n\t| not is_infix\t&& hasprio\n\t\t= (name, False, parseError \"Definition\" No \"Infix operator should be inside parentheses; no infix\" pState)\n\t\t= (name, is_infix, pState)\n\noptionalSpecials :: !ParseState -> (!Specials, !ParseState)\noptionalSpecials pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == SpecialToken\n\t\t# (specials, pState) = wantSpecials pState\n\t\t= (SP_ParsedSubstitutions specials, pState)\n\t\t= (SP_None, tokenBack pState)\n\noptionalFunSpecials :: !ParseState -> (!FunSpecials, !ParseState)\noptionalFunSpecials pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == SpecialToken\n\t\t# (specials, pState) = wantSpecials pState\n\t\t= (FSP_ParsedSubstitutions specials, pState)\n\t\t= (FSP_None, tokenBack pState)\n\nwantSpecials :: !ParseState -> (![Env Type TypeVar], !ParseState)\nwantSpecials pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t pState = begin_special_group token pState\n\t (specials, pState) = wantList \"\" try_substitutions pState\n\t= (specials, end_special_group pState)\nwhere\n\ttry_substitutions pState\n\t\t# (succ, type_var, pState) = tryTypeVar pState\n\t\t| succ\n\t\t\t# (subst, pState) = want_rest_substitutions type_var pState\n\t\t\t= (True, subst, wantEndOfDefinition \"substitution\" pState)\n\t\t\t= (False, [], pState)\n\n\twant_rest_substitutions type_var pState\n\t\t# pState = wantToken GeneralContext \"specials\" EqualToken pState\n\t\t (type, pState) = want pState\n\t\t (token, pState) = nextToken GeneralContext pState\n\t\t| token == CommaToken\n\t\t\t# (next_type_var, pState) = want pState\n\t\t\t (substs, pState) = want_rest_substitutions next_type_var pState\n\t\t\t= ([{ bind_src = type, bind_dst = type_var } : substs], pState)\n\t\t\t= ([{ bind_src = type, bind_dst = type_var }], tokenBack pState)\n\n\tbegin_special_group token pState \/\/ For JvG layout\n\t\t# (token, pState)\n\t\t\t= case token of\n\t\t\t\tSemicolonToken\t->\tnextToken TypeContext pState\n\t\t\t\t_\t\t\t\t->\t(token, pState)\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t| ss_useLayout\n\t\t\t| token == CurlyOpenToken \n\t\t\t\t= parseError \"substitution\" (Yes CurlyOpenToken) \"in layout mode the keyword where is\" pState\n\t\t\t\/\/ otherwise\n\t\t\t\t= tokenBack pState\n\t\t\/\/ not ss_useLayout\n\t\t\t| token == CurlyOpenToken \n\t\t\t\t= pState\n\t\t\t\/\/ otherwise\n\t\t\t\t= tokenBack (parseError \"substitution\" (Yes token) \"{\" pState) \n\n\tend_special_group pState\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| token == EndOfFileToken && ss_useLayout\n\t\t\t= tokenBack pState\n\t\t| ss_useLayout\n\t\t\t= case token of\n\t\t\t\tEndGroupToken\t->\tpState\n\t\t\t\t_\t\t\t\t->\tparseError \"substitution\" (Yes token) \"end of substitution with layout\" pState\n\t\t\/\/ ~ ss_useLayout\n\t\t| token == CurlyCloseToken\n\t\t\t= pState\n\t\t\/\/ otherwise \/\/ token <> CurlyCloseToken\n\t\t\t= parseError \"substitution\" (Yes token) \"end of substitution with layout, },\" pState\n\n\/*\n\tFor parsing right-hand sides of functions only\n*\/\n\nwantCodeRhs :: !ParseState -> (Rhs, !ParseState)\nwantCodeRhs pState\n\t# (expr, pState)\t= want_code_expr pState\n\t (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t= (\t{ rhs_alts\t\t= UnGuardedExpr\n\t\t\t\t\t\t\t{ ewl_nodes\t\t= []\n\t\t\t\t\t\t\t, ewl_locals\t= LocalParsedDefs []\n\t\t\t\t\t\t\t, ewl_expr\t\t= expr\n\t\t\t\t\t\t\t, ewl_position\t= LinePos file_name line_nr\n\t\t\t\t\t\t\t}\n\t\t, rhs_locals\t= LocalParsedDefs []\n\t\t}\n\t , wantEndCodeRhs pState\n\t )\nwhere\n\twant_code_expr :: !ParseState -> (!ParsedExpr, !ParseState)\n\twant_code_expr pState\n\t\t# (token, pState) = nextToken CodeContext pState\n\t\t= case token of\n\t\t\tOpenToken\n\t\t\t\t#\t(input, pState)\t= want_bindings [] True pState\n\t\t\t\t\tpState\t\t\t= wantToken CodeContext \"input bindings of code block\" CloseToken pState\n\t\t\t\t\tpState\t\t\t= wantToken CodeContext \"output bindings of code block\" OpenToken pState\n\t\t\t\t\t(out, pState)\t= want_bindings [] False pState\n\t\t\t\t\tpState\t\t\t= wantToken CodeContext \"output bindings of code block\" CloseToken pState\n\t\t\t\t\t(token, pState)\t= nextToken CodeContext pState\n\t\t\t\t->\tcase token of\n\t\t\t\t\t\tCodeBlockToken the_code\n\t\t\t\t\t\t\t-> (PE_Any_Code input out the_code, pState)\n\t\t\t\t\t\t_\t-> (PE_Any_Code input out [] , parseError \"code rhs (any code)\" (Yes token) \"code block\" pState)\n\t\t\tInlineToken\n\t\t\t \t#\t(token, pState) = nextToken CodeContext pState\n\t\t\t \t->\tcase token of\n\t\t\t \t\t\tCodeBlockToken the_code\n\t\t\t \t\t\t\t-> (PE_ABC_Code the_code True, pState)\n\t\t\t \t\t\ttoken\n\t\t\t \t\t\t\t-> (PE_ABC_Code [] True, parseError \"inline code\" (Yes token) \"code block\" pState)\n\t\t\tCodeBlockToken the_code\n\t\t\t\t-> (PE_ABC_Code the_code False, pState)\n\t\t\ttoken\n\t\t\t\t-> (PE_Empty, parseError \"code rhs\" (Yes token) \"\" pState)\n\n\twant_bindings :: !(CodeBinding Ident) !Bool !ParseState -> (!CodeBinding Ident, !ParseState)\n\twant_bindings acc mayBeEmpty pState\n\t\t# (token, pState)\t= nextToken CodeContext pState\n\t\t= case token of\n\t\t\tIdentToken name\n\t\t\t\t#\t(token, pState)\t= nextToken CodeContext pState\n\t\t\t\t|\ttoken == EqualToken\n\t\t\t\t\t#\t(token, pState)\t= nextToken CodeContext pState\n\t\t\t\t\t->\tcase token of\n\t\t\t\t\t\t\tIdentToken value\n\t\t\t\t\t\t\t\t#\t(ident, pState)\t= stringToIdent name IC_Expression pState\n\t\t\t\t\t\t\t\t\tacc\t\t\t\t= [{ bind_dst = ident, bind_src = value }: acc]\n\t\t\t\t\t\t\t\t\t(token, pState)\t= nextToken CodeContext pState\n\t\t\t\t\t\t\t\t|\ttoken == CommaToken\n\t\t\t\t\t\t\t\t\t->\twant_bindings acc mayBeEmpty pState\n\t\t\t\t\t\t\t\t\/\/\ttoken <> CommaToken\n\t\t\t\t\t\t\t\t\t->\t(reverse acc, tokenBack pState)\n\t\t\t\t\t\t\ttoken\n\t\t\t\t\t\t\t\t-> (acc, parseError \"bindings in code block\" (Yes token) \"value\" pState)\n\t\t\t\t\/\/\ttoken <> EqualToken\n\t\t\t\t\t->\t(acc, parseError \"bindings in code block\" (Yes token) \"= or =:\" pState)\n\t\t\tCloseToken\n\t\t\t\t| mayBeEmpty\n\t\t\t\t\t-> (acc, tokenBack pState) \/\/ to handle empty input bindings\n\t\t\t\t\t-> (acc, parseError \"code bindings\" (Yes token) \"output bindings\" pState)\n\t\t\ttoken\n\t\t\t\t-> (acc, parseError \"bindings in code block\" (Yes token) \"identifier\" pState)\n\/*\n\tFor parsing right-hand sides of functions and case expressions\n*\/\n\/* Syntax:\n\tFunctionAltDefRhs\t=\tFunctionBody\t\t\t\t\t\t\/\/ Rhs\n\t\t\t\t\t\t\t[ LocalFunctionAltDefs ]\n\tFunctionBody\t\t=\texprWithLocals\t\t\t\t\t\t\/\/ OptGuardedAlts\t: GuardedAlts\n\t\t\t\t\t\t|\tGuardedAlts \t\t\t\t\t\t\/\/\t\t\t\t\t: UnGuardedExpr\n\tGuardedAlts\t\t\t=\t{ [ LetBefore ] '|' [ StrictLet ] Guard FunctionBody }+ [ ExprWithLocals ]\n\tExprWithLocals\t\t=\t[ LetBefore ] sep RootExpression endOfDefinition [ LocalFunctionDefs ]\n*\/\n\n:: RhsDefiningSymbol\n\t=\tRhsDefiningSymbolExact Token\n\t|\tRhsDefiningSymbolCase\t\t\t\/\/ '->' or '='\n\t|\tRhsDefiningSymbolGlobalFunction\t\/\/ '=', '=:', '=>'\n\t|\tRhsDefiningSymbolGlobalFunctionOrMacro\t\/\/ '=', '=:', '=>', ':=='\n\t|\tRhsDefiningSymbolRule\t\t\t\/\/ '=', '=>'\n\t|\tRhsDefiningSymbolRuleOrMacro\t\/\/ '=', '=>', ':=='\n\nruleDefiningRhsSymbol :: !ParseContext !Bool -> RhsDefiningSymbol\nruleDefiningRhsSymbol parseContext has_args\n\t| isGlobalOrClassDefsContext parseContext\n\t\t| has_args\n\t\t\t= RhsDefiningSymbolRuleOrMacro\n\t\t\t= RhsDefiningSymbolGlobalFunctionOrMacro\n\t| isInstanceDefsContext parseContext\n\t\t| has_args\n\t\t\t= RhsDefiningSymbolRule\n\t\t\t= RhsDefiningSymbolGlobalFunction\n\t\t= RhsDefiningSymbolRule\n\nisDefiningSymbol :: RhsDefiningSymbol Token -> Bool\nisDefiningSymbol (RhsDefiningSymbolExact wanted) observed\n\t=\twanted == observed\nisDefiningSymbol RhsDefiningSymbolCase observed\n\t=\tobserved == EqualToken || observed == ArrowToken\nisDefiningSymbol RhsDefiningSymbolRule observed\n\t=\tobserved == EqualToken || observed == DoubleArrowToken\nisDefiningSymbol RhsDefiningSymbolGlobalFunctionOrMacro observed\n\t=\tobserved == EqualToken || observed == ColonDefinesToken || observed == DefinesColonToken || observed == DoubleArrowToken\nisDefiningSymbol RhsDefiningSymbolRuleOrMacro observed\n\t=\tobserved == EqualToken || observed == ColonDefinesToken || observed == DoubleArrowToken\nisDefiningSymbol RhsDefiningSymbolGlobalFunction observed\n\t=\tobserved == EqualToken || observed == ColonDefinesToken || observed == DefinesColonToken\n\ndefiningSymbolToFunKind :: RhsDefiningSymbol -> FunKind\ndefiningSymbolToFunKind (RhsDefiningSymbolExact defining_token)\n\t=\tdefiningTokenToFunKind defining_token\ndefiningSymbolToFunKind _\n\t=\tFK_Unknown\n\ndefiningTokenToFunKind :: Token -> FunKind\ndefiningTokenToFunKind ColonDefinesToken\n\t=\tFK_Macro\ndefiningTokenToFunKind EqualToken\n\t=\tFK_Function cNameNotLocationDependent\ndefiningTokenToFunKind DoubleArrowToken\n\t=\tFK_Function cNameNotLocationDependent\ndefiningTokenToFunKind DefinesColonToken\n\t=\tFK_Caf\ndefiningTokenToFunKind _\n\t=\tFK_Unknown\n\nwantRhs_without_where :: !Token !Bool !RhsDefiningSymbol !ParseState -> (!Rhs, !RhsDefiningSymbol, !ParseState) \/\/ FunctionAltDefRhs\nwantRhs_without_where token localsExpected definingSymbol pState\n\t# (nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t (alts, definingSymbol, pState) = want_FunctionBody token nodeDefs [] definingSymbol pState\n\t= ({ rhs_alts = alts, rhs_locals = LocalParsedDefs []}, definingSymbol, pState)\nwhere\n\twant_FunctionBody :: !Token ![NodeDefWithLocals] ![GuardedExpr] !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState)\n\twant_FunctionBody BarToken nodeDefs alts definingSymbol pState\n\t\t#\t(file_name, line_nr, pState)= getFileAndLineNr pState\n\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t|\ttoken == OtherwiseToken\n\t\t\t#\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs2, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t= want_FunctionBody token (nodeDefs ++ nodeDefs2) alts definingSymbol pState \/\/ to allow | otherwise | c1 = .. | c2 = ..\n\t\t|\ttoken == LetToken True\n\t\t\t#\tpState\t= parseError \"RHS\" No \"No 'let!' in this version of Clean\" pState\n\t\t\t=\troot_expression token nodeDefs (reverse alts) definingSymbol pState\n\t\t#\t(guard, pState)\t\t\t\t= wantExpressionT token pState\n\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t(nodeDefs2, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t|\ttoken == BarToken \/\/ nested guard\n\t\t\t#\t(position, pState)\t\t\t= getPosition pState\n\t\t\t\toffside\t\t\t\t\t\t= position.fp_col\n\t\t\t\t(expr, definingSymbol, pState)\n\t\t\t\t\t\t\t\t\t\t\t= want_FunctionBody token nodeDefs2 [] definingSymbol pState\n\t\t\t\tpState\t\t\t\t\t\t= wantEndNestedGuard (default_found expr) offside pState\n\t\t\t\talt\t\t\t\t\t\t\t= { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr,\n\t\t\t\t\t\t\t\t\t\t\t\talt_ident = guard_ident line_nr, alt_position = LinePos file_name line_nr }\n\t\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t=\twant_FunctionBody token nodeDefs [alt:alts] definingSymbol pState\n\t\t\/\/ otherwise\n\t\t\t#\t(expr, definingSymbol, pState)\n\t\t\t\t\t\t\t\t\t\t\t= root_expression token nodeDefs2 [] definingSymbol pState\n\t\t\t\talt\t\t\t\t\t\t\t= { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr,\n\t\t\t\t\t\t\t\t\t\t\t\talt_ident = guard_ident line_nr, alt_position = LinePos file_name line_nr }\n\t\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t=\twant_FunctionBody token nodeDefs [alt:alts] definingSymbol pState\n\t where\n\t \tguard_ident line_nr\n\t\t\t= { id_name = \"_g;\" +++ toString line_nr +++ \";\", id_info = nilPtr }\n\twant_FunctionBody token nodeDefs alts definingSymbol pState\n\t\t=\troot_expression token nodeDefs (reverse alts) definingSymbol pState\n\n\troot_expression :: !Token ![NodeDefWithLocals] ![GuardedExpr] !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState)\n\troot_expression token nodeDefs alts definingSymbol pState\n\t\t# (optional_expr,definingSymbol,pState) = want_OptExprWithLocals token nodeDefs definingSymbol pState\n\t\t= build_root token optional_expr alts nodeDefs definingSymbol pState\n\n\twant_OptExprWithLocals :: !Token ![NodeDefWithLocals] !RhsDefiningSymbol !ParseState -> (!Optional ExprWithLocalDefs, !RhsDefiningSymbol, !ParseState)\n\twant_OptExprWithLocals token nodeDefs definingSymbol pState\n\t\t| isDefiningSymbol definingSymbol token\n\t\t# (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t\t (expr, pState)\t= wantExpression pState\n\t\t locals = LocalParsedDefs []\n\t\t= ( Yes\t{ ewl_nodes\t\t= nodeDefs\n\t\t\t\t, ewl_expr\t\t= expr\n\t\t\t\t, ewl_locals\t= locals\n\t\t\t\t, ewl_position\t= LinePos file_name line_nr\n\t\t\t\t}\n\t\t , RhsDefiningSymbolExact token\n\t\t , pState\n\t\t )\n\t\t= (No, definingSymbol, tokenBack pState)\n\nwantRhs :: !Bool !RhsDefiningSymbol !ParseState -> (!Rhs, !RhsDefiningSymbol, !ParseState) \/\/ FunctionAltDefRhs\nwantRhs localsExpected definingSymbol pState\n\t# (alts, definingSymbol, pState)\t= want_LetsFunctionBody definingSymbol pState\n\t (locals, pState)\t= optionalLocals WhereToken localsExpected pState\n\t= ({ rhs_alts = alts, rhs_locals = locals}, definingSymbol, pState)\nwhere\n\twant_LetsFunctionBody :: !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState) \n\twant_LetsFunctionBody definingSymbol pState\n\t\t# (token, pState)\t\t\t= nextToken FunctionContext pState\n\t\t (nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t= want_FunctionBody token nodeDefs [] definingSymbol pState\n\n\twant_FunctionBody :: !Token ![NodeDefWithLocals] ![GuardedExpr] !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState)\n\twant_FunctionBody BarToken nodeDefs alts definingSymbol pState\n\/\/\t\t#\t(lets, pState)\t\t\t\t= want_StrictLet pState \/\/ removed from 2.0\n\t\t#\t(file_name, line_nr, pState)= getFileAndLineNr pState\n\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t|\ttoken == OtherwiseToken\n\t\t\t#\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs2, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t= want_FunctionBody token (nodeDefs ++ nodeDefs2) alts definingSymbol pState \/\/ to allow | otherwise | c1 = .. | c2 = ..\n\t\t|\ttoken == LetToken True\n\t\t\t#\tpState\t= parseError \"RHS\" No \"No 'let!' in this version of Clean\" pState\n\t\t\t=\troot_expression True token nodeDefs (reverse alts) definingSymbol pState\n\t\t#\t(guard, pState)\t\t\t\t= wantExpressionT token pState\n\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t(nodeDefs2, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t|\ttoken == BarToken \/\/ nested guard\n\t\t\t#\t(position, pState)\t\t\t= getPosition pState\n\t\t\t\toffside\t\t\t\t\t\t= position.fp_col\n\t\t\t\t(expr, definingSymbol, pState)\n\t\t\t\t\t\t\t\t\t\t\t= want_FunctionBody token nodeDefs2 [] definingSymbol pState\n\t\t\t\tpState\t\t\t\t\t\t= wantEndNestedGuard (default_found expr) offside pState\n\t\t\t\talt\t\t\t\t\t\t\t= { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr,\n\t\t\t\t\t\t\t\t\t\t\t\talt_ident = guard_ident line_nr, alt_position = LinePos file_name line_nr }\n\t\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t=\twant_FunctionBody token nodeDefs [alt:alts] definingSymbol pState\n\t\t\/\/ otherwise\n\t\t\t#\t(expr, definingSymbol, pState)\n\t\t\t\t\t\t\t\t\t\t\t= root_expression True token nodeDefs2 [] definingSymbol pState\n\t\t\t\talt\t\t\t\t\t\t\t= { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr,\n\t\t\t\t\t\t\t\t\t\t\t\talt_ident = guard_ident line_nr, alt_position = LinePos file_name line_nr }\n\t\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t=\twant_FunctionBody token nodeDefs [alt:alts] definingSymbol pState\n\t where\n\t \tguard_ident line_nr\n\t\t\t= { id_name = \"_g;\" +++ toString line_nr +++ \";\", id_info = nilPtr }\n\twant_FunctionBody token nodeDefs alts definingSymbol pState\n\t\t=\troot_expression localsExpected token nodeDefs (reverse alts) definingSymbol pState\n\n\troot_expression :: !Bool !Token ![NodeDefWithLocals] ![GuardedExpr] !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState)\n\troot_expression withExpected token nodeDefs alts definingSymbol pState\n\t\t# (optional_expr,definingSymbol,pState) = want_OptExprWithLocals withExpected token nodeDefs definingSymbol pState\n\t\t= build_root token optional_expr alts nodeDefs definingSymbol pState\n\n\twant_OptExprWithLocals :: !Bool !Token ![NodeDefWithLocals] !RhsDefiningSymbol !ParseState -> (!Optional ExprWithLocalDefs, !RhsDefiningSymbol, !ParseState)\n\/\/\twant_OptExprWithLocals withExpected DoubleArrowToken nodeDefs pState\n\/\/\t\t= want_OptExprWithLocals True EqualToken nodeDefs (replaceToken EqualToken pState)\n\twant_OptExprWithLocals withExpected token nodeDefs definingSymbol pState\n\t\t| isDefiningSymbol definingSymbol token\n\t\t# (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t\t (expr, pState)\t= wantExpression pState\n\t\t pState\t\t\t= wantEndRootExpression pState\n\t\t (locals,pState)\t= optionalLocals WithToken withExpected pState\n\t\t= ( Yes\t{ ewl_nodes\t\t= nodeDefs\n\t\t\t\t, ewl_expr\t\t= expr\n\t\t\t\t, ewl_locals\t= locals\n\t\t\t\t, ewl_position\t= LinePos file_name line_nr\n\t\t\t\t}\n\t\t , RhsDefiningSymbolExact token\n\t\t , pState\n\t\t )\n\t\t= (No, definingSymbol, tokenBack pState)\n\nbuild_root :: !Token !(Optional ExprWithLocalDefs) ![GuardedExpr] ![NodeDefWithLocals] !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState)\nbuild_root _ (Yes expr) [] _ definingSymbol pState\n\t= ( UnGuardedExpr expr, definingSymbol, pState)\nbuild_root _ No alts=:[_:_] [] definingSymbol pState\n\t= (GuardedAlts alts No, definingSymbol, pState)\nbuild_root _ optional_expr alts=:[_:_] _ definingSymbol pState\n\t= (GuardedAlts alts optional_expr, definingSymbol, pState)\nbuild_root token _ _ _ definingSymbol pState\n\t# (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t=\t(UnGuardedExpr {ewl_nodes = [], ewl_expr = PE_Empty, ewl_locals = LocalParsedDefs [],\n\t\t\t\t\t\t\t\t\t\tewl_position = LinePos file_name line_nr}\n\t\t\t\t\t, definingSymbol\n\t\t\t\t\t, parseError \"RHS: root expression\" (Yes token) \"= \" pState\n\t\t\t\t\t)\n\ndefault_found (GuardedAlts _ No)\t= False\ndefault_found _\t\t\t\t\t\t= True\n\n\/*\twant_StrictLet :: !ParseState -> ([NodeDefWithLocals] , !ParseState) \/\/ Removed from the language !?\n\twant_StrictLet pState\n\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t| token == LetToken True\n\t\t\t# (let_defs, pState)\t= wantList \"\" (try_LetDef True) pState\n\t\t\t pState\t\t\t\t= wantToken FunctionContext \"strict let\" InToken pState\n\t\t\t= (let_defs, pState)\n\t\t= ([], tokenBack pState)\n*\/\nwant_LetBefores :: !Token !Bool !ParseState -> (![NodeDefWithLocals], !Token, !ParseState)\nwant_LetBefores (SeqLetToken strict) localsExpected pState\n\t# (let_defs, pState)\t\t\t\t= wantList \"\" (try_LetDef strict) pState\n\t (token, pState)\t\t\t\t\t= nextToken FunctionContext pState\n\t (token, pState)\t\t\t\t\t= opt_End_Group token pState\n\t (more_let_defs, token, pState)\t= want_LetBefores token localsExpected pState\n\t= (let_defs ++ more_let_defs, token, pState)\nwhere\n\topt_End_Group token pState\n\t #\t(ss_useLayout, pState) = accScanState UseLayout pState\n\t |\tss_useLayout\n\t \t| token == EndGroupToken\n\t \t\t= nextToken FunctionContext pState\n\t \t\/\/ otherwise \/\/ token <> EndGroupToken\n\t \t\t= (ErrorToken \"End group missing in let befores\", parseError \"RHS: Let befores\" (Yes token) \"Generated End Group (due to layout)\" pState)\n\t |\totherwise \/\/ not ss_useLayout\n\t =\t(token, pState)\n\n\ttry_LetDef :: !Bool !ParseState -> (!Bool, NodeDefWithLocals, !ParseState)\n\ttry_LetDef strict pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tIdentToken name\n\t\t\t\t| isLowerCaseName name\n\t\t\t\t\t# (id, pState) = stringToIdent name IC_Expression pState\n\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t| token == DefinesColonToken\n\t\t\t\t\t\t# (succ, expr, pState) = trySimplePattern pState\n\t\t\t\t\t\t| succ\n\t\t\t\t\t\t\t# lhs_exp = PE_Bound { bind_dst = id, bind_src = expr }\n\t\t\t\t\t\t\t-> parse_let_rhs lhs_exp pState\n\t\t\t\t\t\t\t# pState = parseError \"simple expression\" No \"expression\" pState\n\t\t\t\t\t\t\t lhs_exp = PE_Empty\n\t\t\t\t\t\t\t-> parse_let_rhs lhs_exp pState\n\n\t\t\t\t\t| token == AndToken\n\t\t\t\t\t\t# lhs_exp = PE_Ident id\n\t\t\t\t\t\t (file_name, line_nr, pState) = getFileAndLineNr pState\n\t\t\t\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t (update_exp, pState) = want_update_without_curly_close NoRecordName lhs_exp token pState\n\t\t\t\t\t\t pState = wantEndRootExpression pState\n\t\t\t\t \t \t (locals , pState) = optionalLocals WithToken localsExpected pState\n\t\t\t\t\t\t ndwl = {\tndwl_strict\t= strict\n\t\t\t\t\t\t\t\t ,\tndwl_def\t= { bind_dst = lhs_exp, bind_src = update_exp }\n\t\t\t\t\t\t\t\t , ndwl_locals\t= locals\n\t\t\t\t\t\t\t\t , ndwl_position\n\t\t\t\t\t\t\t\t \t\t\t\t= LinePos file_name line_nr\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t->\t(True, ndwl, pState)\n\t\t\t\t\t\n\t\t\t\t\t\t# lhs_exp = PE_Ident id\n\t\t\t\t\t\t pState = tokenBack pState\n\t\t\t\t\t\t-> parse_let_rhs lhs_exp pState\t\t\t\t\t\n\t\t\t_\n\t\t\t\t# (succ, lhs_exp, pState) = trySimplePatternT token pState\n\t\t\t\t| succ\n\t\t\t\t\t-> parse_let_rhs lhs_exp pState\n\t\t\t\t\t-> (False, abort \"no definition\", pState)\n\twhere\n\t\tparse_let_rhs lhs_exp pState\n\t\t\t# pState\t\t\t= wantToken FunctionContext \"let definition\" EqualToken pState\n\t\t\t (file_name, line_nr, pState)\n\t\t\t \t\t\t\t\t= getFileAndLineNr pState\n\t\t\t (rhs_exp, pState) = wantExpression pState\n\t\t\t pState\t\t\t= wantEndRootExpression pState \/\/ -->> (\"#\",lhs_exp,\"=\",rhs_exp)\n\t \t \t (locals , pState) = optionalLocals WithToken localsExpected pState\n\t\t\t=\t( True\n\t\t\t\t, {\tndwl_strict\t= strict\n\t\t\t\t ,\tndwl_def\t= { bind_dst = lhs_exp\n\t\t\t\t \t\t\t\t , bind_src = rhs_exp\n\t\t\t\t \t\t\t\t }\n\t\t\t\t , ndwl_locals\t= locals\n\t\t\t\t , ndwl_position\n\t\t\t\t \t\t\t\t= LinePos file_name line_nr\n\t\t\t\t }\n\t\t\t\t, pState\n\t\t\t\t)\nwant_LetBefores token localsExpected pState\n\t= ([], token, pState)\n\noptionalLocals :: !Token !Bool !ParseState -> (!LocalDefs, !ParseState)\noptionalLocals dem_token localsExpected pState\n # (off_token, pState) = nextToken FunctionContext pState\n\t| dem_token == off_token\n\t\t= wantLocals pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t| off_token == CurlyOpenToken && ~ ss_useLayout && localsExpected\n\t\t= wantLocals (tokenBack pState)\n\t\/\/ otherwise\n\t\t= (LocalParsedDefs [], tokenBack pState)\n\nwantLocals :: !ParseState -> (LocalDefs, !ParseState)\nwantLocals pState\n\t# pState\t\t\t= wantBeginGroup \"local definitions\" pState\n\t (defs, pState)\t= wantDefinitions cLocalContext pState\n\t= (LocalParsedDefs defs, wantEndLocals pState)\n\n\/*\n\timports and exports\n*\/\n\nwantImports :: !ParseState -> (![ParsedImport], !ParseState)\nwantImports pState\n\t# (imports, pState) = wantModuleImports (IC_Module NoQualifiedIdents) pState\n\t pState = wantEndOfDefinition \"imports\" pState\n\t= (imports, pState)\n\nwantModuleImports :: !IdentClass !ParseState -> (![Import], !ParseState)\nwantModuleImports ident_class pState\n\t# (import_qualified, first_name, pState) = wantOptionalQualifiedAndModuleName pState\n\t (first_ident, pState) = stringToIdent first_name ident_class pState\n\t (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t position = LinePos file_name line_nr\n\t (token, pState) = nextToken FunctionContext pState\n\t (import_qualified,token, pState) = parse_optional_as_module_name import_qualified token pState\n\t module_import = {import_module = first_ident, import_symbols = ImportSymbolsAll, import_file_position = position, import_qualified = import_qualified}\n\t| token == CommaToken\n\t\t# (rest, pState) = wantModuleImports ident_class pState\n\t\t= ([module_import : rest], pState)\n\t= ([module_import], tokenBack pState)\nwhere\n\tparse_optional_as_module_name import_qualified=:Qualified token=:(IdentToken \"as\") pState\n\t\t# (mod_name, pState) = wantModuleName pState\n\t\t (mod_ident, pState) = stringToIdent mod_name (IC_Module NoQualifiedIdents) pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t= (QualifiedAs mod_ident,token,pState)\n\tparse_optional_as_module_name import_qualified token pState\n\t\t= (import_qualified,token,pState)\n\nwantFromImports :: !ParseState -> (!ParsedImport, !ParseState)\nwantFromImports pState\n\t# (mod_name, pState) = wantModuleName pState\n\t (mod_ident, pState) = stringToIdent mod_name (IC_Module NoQualifiedIdents) pState\n\t (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tImportToken\n\t\t\t-> wantOptionalQualifiedAndImportDeclarations mod_ident pState\n\t\tIdentToken \"as\"\n\t\t\t# (as_mod_name, pState) = wantModuleName pState\n\t\t\t (as_mod_ident, pState) = stringToIdent as_mod_name (IC_Module NoQualifiedIdents) pState\n\t\t\t pState = wantToken GeneralContext \"from imports\" ImportToken pState\n\t\t\t pState = wantToken GeneralContext \"from imports\" (IdentToken \"qualified\") pState\t\t\t\t\n\t\t\t (file_name, line_nr, pState) = getFileAndLineNr pState\n\t\t\t (import_symbols, pState) = wantImportDeclarations pState\n\t\t\t pState = wantEndOfDefinition \"from imports\" pState\n\t\t\t-> ({import_module = mod_ident, import_symbols = ImportSymbolsOnly import_symbols,\n\t\t\t\t import_file_position = LinePos file_name line_nr, import_qualified = QualifiedAs as_mod_ident}, pState)\n\t\t_\n\t\t\t# pState = parseError \"from imports\" (Yes token) \"import or as\" pState\n\t\t\t-> wantOptionalQualifiedAndImportDeclarations mod_ident pState\n\twhere\n\twantOptionalQualifiedAndImportDeclarations mod_ident pState\n\t\t# (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t\t (token, pState) = nextToken GeneralContext pState\n\t\t| case token of IdentToken \"qualified\" -> True ; _ -> False\n\t\t\t# (import_symbols, pState) = wantImportDeclarations pState\n\t\t\t pState = wantEndOfDefinition \"from imports\" pState\n\t\t\t= ( { import_module = mod_ident, import_symbols = ImportSymbolsOnly import_symbols,\n\t\t\t\t import_file_position = LinePos file_name line_nr, import_qualified = Qualified }, pState)\n\t\t# (import_symbols, pState) = wantImportDeclarationsT token pState\n\t\t pState = wantEndOfDefinition \"from imports\" pState\n\t\t= ( { import_module = mod_ident, import_symbols = ImportSymbolsOnly import_symbols,\n\t\t\t import_file_position = LinePos file_name line_nr, import_qualified = NotQualified }, pState)\n\n\twantImportDeclarations pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t= wantImportDeclarationsT token pState\n\n\twantImportDeclarationsT token pState\n\t\t# (first, pState) = wantImportDeclarationT token pState\n\t\t (token, pState) = nextToken GeneralContext pState\n\t\t| token == CommaToken\n\t\t\t# (rest, pState) = wantImportDeclarations pState\n\t\t\t= ([first : rest], pState)\n\t\t\t= ([first], tokenBack pState)\n\ninstance want ImportedObject where\n\twant pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t| token == IdentToken \"library\"\n\t \t\t# (token, pState) = nextToken GeneralContext pState\n\t\t\t= want_import_string token cIsImportedLibrary pState\n\t\t\t= want_import_string token cIsImportedObject pState\n\t\twhere\t\t\n\t\t\twant_import_string :: Token Bool ParseState -> (ImportedObject, ParseState)\n\t\t\twant_import_string (StringToken string) isLibrary pState\n\t\t\t\t=\t({io_is_library = isLibrary, io_name = string}, pState)\n\t\t\twant_import_string token isLibrary pState\n\t\t\t\t=\t({io_is_library = isLibrary, io_name = \"\"}, parseError \"import code declaration\" (Yes token) \"imported item\" pState)\n\nwantCodeImports :: !ParseState -> (![ImportedObject], !ParseState)\nwantCodeImports pState\n\t# pState = wantToken GeneralContext \"import code declaration\" FromToken pState\n\t (importObjects, pState) = wantSequence CommaToken GeneralContext pState\n\t= (importObjects, wantEndOfDefinition \"import code declaration\" pState)\n\ninstance want ImportDeclaration\nwhere\n\twant pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t= wantImportDeclarationT token pState\n\nwantImportDeclarationT token pState\n\t= case token of\n\t\tDoubleColonToken\n\t\t\t# (name, pState)\t\t\t\t= wantConstructorName \"import type\" pState\n\t\t\t (type_id, pState)\t\t\t\t= stringToIdent name IC_Type pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == OpenToken\n\t\t\t \t#\t(conses, pState)\t\t\t= want_names (wantConstructorName \"import type (..)\") IC_Expression CloseToken pState\n\t\t\t \t->\t(ID_Type type_id (Yes conses), pState)\n\t\t\t| token == CurlyOpenToken\n\t\t\t \t#\t(fields, pState) = want_names (wantLowerCaseName \"import record fields\") (IC_Field type_id) CurlyCloseToken pState\n\t\t\t \t->\t(ID_Record type_id (Yes fields), pState)\n\t\t\t \t->\t(ID_Type type_id No, tokenBack pState)\n\t\tClassToken\n\t\t\t# (name, pState)\t\t\t\t= want pState\n\t\t\t (class_id, pState)\t\t\t= stringToIdent name IC_Class pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == OpenToken\n\t\t\t \t#\t(members, pState)\t\t\t= want_names want IC_Expression CloseToken pState\n\t\t\t \t->\t(ID_Class class_id (Yes members), pState)\n\t\t\t \t->\t(ID_Class class_id No, tokenBack pState)\n\t\tInstanceToken\n\t\t\t#\t(class_name, pState)\t= want pState\n\t\t\t\t(types, pState)\t\t\t= wantList \"instance types\" tryBrackType pState\n\t\t\t\t(class_id, pState)\t\t= stringToIdent class_name IC_Class pState\n\t\t\t\t(inst_id, pState)\t\t= stringToIdent class_name (IC_Instance types) pState\n\t\t\t\t(context, pState)\t\t= optionalContext pState\n\t\t\t->\t(ID_Instance class_id inst_id (types,context), pState)\n\t\tIdentToken fun_name\n\t\t\t#\t(fun_id, pState)\t\t= stringToIdent fun_name IC_Expression pState\n\t\t\t\t(ii_extended, pState)\t= optional_extension pState\n\t\t\t->\t(ID_Function fun_id, pState)\n\t\tGenericToken\n\t\t\t#\t(name, pState)\t\t\t= want pState\n\t\t\t\t(generic_id, pState)\t= stringToIdent name IC_Generic pState\n\t\t\t\t(expr_id, pState)\t\t= stringToIdent name IC_Expression pState\n\t\t \t->\t(ID_Generic generic_id expr_id, pState)\n\t\ttoken\n\t\t\t#\t(fun_id, pState)\t\t= stringToIdent \"dummy\" IC_Expression pState\n\t\t\t->\t( ID_Function fun_id\n\t\t\t\t, parseError \"from import\" (Yes token) \"imported item\" pState\n\t\t\t\t)\nwhere\t\t\t\t\n\twant_names want_fun ident_kind close_token pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == DotDotToken\n\t\t\t= ([], wantToken FunctionContext \"import declaration\" close_token pState)\n\t\t\t= want_list_of_names want_fun ident_kind close_token (tokenBack pState)\n\n\twant_list_of_names want_fun ident_kind close_token pState\n\t\t# (name, pState) = want_fun pState\n\t\t (name_id, pState)\t= stringToIdent name ident_kind pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (names, pState) = want_list_of_names want_fun ident_kind close_token pState\n\t\t\t= ([name_id : names], pState)\n\t\t| token == close_token\n\t\t\t= ([name_id], pState)\n\t\t\t= ([name_id], parseError \"ImportDeclaration\" (Yes token) \")\" pState)\n\t\t\n\toptional_extension pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == DotDotToken\n\t\t\t= (True, pState)\n\t\t\t= (False, tokenBack pState)\t\t\t\n\n\/*\n\tClasses and instances\n*\/\n\ncIsAGlobalContext\t\t:== True\ncIsNotAGlobalContext\t:== False\n\ncMightBeAClass\t\t\t:== True\ncIsNotAClass\t\t\t:== False\n\n\t\t\nwantClassDefinition :: !ParseContext !Position !ParseState -> (!ParsedDefinition, !ParseState)\nwantClassDefinition parseContext pos pState\n\t# (might_be_a_class, class_or_member_name, prio, pState) = want_class_or_member_name pState\n\t (class_variables, pState) = wantList \"class variable(s)\" try_class_variable pState\n\t (class_arity, class_args, class_fun_dep_vars, class_cons_vars) = convert_class_variables class_variables 0 0 0\n\t (contexts, pState) = optionalContext pState\n \t (token, pState) = nextToken TypeContext pState\n \t| token == DoubleColonToken\n\t\t= want_overloaded_function pos class_or_member_name prio class_arity class_args class_fun_dep_vars class_cons_vars contexts pState\n\t| might_be_a_class\n\t\t# (begin_members, pState) = begin_member_group token pState\n\t\t| begin_members\n\t\t\t# (class_id, pState) = stringToIdent class_or_member_name IC_Class pState\n\t\t \t (members, pState) = wantDefinitions (SetClassDefsContext parseContext) pState\n \t\t \t class_def = { class_ident = class_id, class_arity = class_arity, class_args = class_args,\n\t \t\t\t\t\tclass_context = contexts, class_pos = pos, class_members = {}, class_cons_vars = class_cons_vars,\n\t \t\t\t\t\tclass_fun_dep_vars = class_fun_dep_vars, class_lazy_members = 0,\n\t \t\t\t\t\tclass_dictionary = { ds_ident = { class_id & id_info = nilPtr }, ds_arity = 0, ds_index = NoIndex}\n\t\t\t\t\t\t }\n\t \t pState = wantEndGroup \"class\" pState\n\t\t\t= (PD_Class class_def members, pState)\n\t\t| isEmpty contexts\n\t\t\t= (PD_Erroneous, parseError \"Class Definition\" (Yes token) \": contexts\" pState)\n\t\t\/\/ otherwise\n\t\t\t# pState = tokenBack pState\n\t\t\t (class_id, pState) = stringToIdent class_or_member_name IC_Class pState\n \t\t\t class_def = { class_ident = class_id, class_arity = class_arity, class_args = class_args,\n\t\t\t\t\t\t\tclass_context = contexts, class_pos = pos, class_members = {}, class_cons_vars = class_cons_vars,\n\t\t\t\t\t\t\tclass_fun_dep_vars = class_fun_dep_vars, class_lazy_members = 0,\n\t\t\t\t\t\t\tclass_dictionary = { ds_ident = { class_id & id_info = nilPtr }, ds_arity = 0, ds_index = NoIndex }\n\t\t\t\t\t\t }\n\t \t\t pState = wantEndOfDefinition \"class definition\" pState\n\t\t\t= (PD_Class class_def [], pState)\n\t\t= (PD_Erroneous, parseError \"Class Definition\" (Yes token) \"\" pState)\n\twhere\n\t\tbegin_member_group token pState \/\/ For JvG layout\n\t\t\t# (token, pState)\n\t\t\t\t= case token of\n\t\t\t\t\tSemicolonToken\t->\tnextToken TypeContext pState\n\t\t\t\t\t_\t\t\t\t->\t(token, pState)\n\t\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t\t| token == WhereToken\n\t\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t\t| token == CurlyOpenToken\n\t\t\t\t\t| ss_useLayout\n\t\t\t\t\t\t= (True, parseError \"class definition\" No \"No { in layout mode\" pState) \n\t\t\t\t\t\t= (True, pState)\n\t\t\t\t\t= (True, tokenBack pState)\n\t\t\t| token == CurlyOpenToken \n\t\t\t\t| ss_useLayout\n\t\t\t\t\t= (True, parseError \"class definition\" (Yes CurlyOpenToken) \"in layout mode the keyword where is\" pState) \n\t\t\t\t\t= (True, pState)\n\t\t\t\t= (False, pState) \/\/ token is still known: no tokenBack\n\t\t\n\t\twant_class_or_member_name pState \n\/\/ PK\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t\t| token == OpenToken\n\t\t\t\t# (member_name, pState) = want pState\n\t\t\t\t pState = wantToken GeneralContext \"class definition\" CloseToken pState\n\t\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t\t (prio, pState) = optionalPriority cIsInfix token pState \n\t\t\t\t= (cIsNotAClass, member_name, prio, pState)\n \t\t\t\t# (class_ident, pState) = want_name token pState\n\t\t\t\t= (cMightBeAClass, class_ident, NoPrio, pState)\n\t\twhere\n\t\t\twant_name (IdentToken name) pState\n\t\t\t\t= (name, pState)\n\t\t\twant_name token pState\n\t\t\t\t= (\"\", parseError \"Class Definition\" (Yes token) \"\" pState)\n\n\t\twant_overloaded_function pos member_name prio class_arity class_args class_fun_dep_vars class_cons_vars contexts pState\n\t\t\t# (tspec, pState) = wantSymbolType pState\n\t\t\t (member_id, pState) = stringToIdent member_name IC_Expression pState\n\t\t\t (class_id, pState) = stringToIdent member_name IC_Class pState\n\t\t\t member = PD_TypeSpec pos member_id prio (Yes tspec) FSP_None\n\t\t\t class_def = {\tclass_ident = class_id, class_arity = class_arity, class_args = class_args,\n\t\t \t\t\t\tclass_context = contexts, class_pos = pos, class_members = {}, class_cons_vars = class_cons_vars,\n\t\t \t\t\t\tclass_fun_dep_vars = class_fun_dep_vars, class_lazy_members = 0,\n \t\t\t\t\t\t\tclass_dictionary = { ds_ident = { class_id & id_info = nilPtr }, ds_arity = 0, ds_index = NoIndex }\n \t\t\t\t\t\t }\n\t \t\t pState = wantEndOfDefinition \"overloaded function\" pState\n\t\t\t= (PD_Class class_def [member], pState)\n\n\t\ttry_class_variable pState\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= case token of\n\t\t\t\tIdentToken \"~\"\n\t\t\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t\t\t-> case token of\n\t\t\t\t\t\tDotToken\n\t\t\t\t\t\t\t# (type_var, pState) = wantTypeVar pState\n\t\t\t\t\t\t\t= (True, (1, 1, type_var), pState)\n\t\t\t\t\t\t_\n\t\t\t\t\t\t\t# (type_var, pState) = wantTypeVarT token pState\n\t\t\t\t\t\t\t= (True, (1, 0, type_var), pState)\n\t\t\t\tDotToken\n\t\t\t\t\t# (type_var, pState) = wantTypeVar pState\n\t\t\t\t\t-> (True, (0, 1, type_var), pState)\n\t\t\t\t_\n\t\t\t\t\t# (succ, type_var, pState) = tryTypeVarT token pState\n\t\t\t\t\t-> (succ, (0, 0, type_var), pState)\n\n\t\tconvert_class_variables [(fun_dep_var, annot, var) : class_vars] arg_nr fun_dep_vars cons_vars\n\t\t\t# (arity, class_vars, fun_dep_vars, cons_vars)\n\t\t\t\t= convert_class_variables class_vars (arg_nr+1) fun_dep_vars cons_vars\n\t\t\t#! fun_dep_vars = (fun_dep_vars<<1) bitor fun_dep_var\n\t\t\t cons_vars = (cons_vars<<1) bitor annot\n\t\t\t= (arity, [var : class_vars], fun_dep_vars, cons_vars)\n\t\tconvert_class_variables [] arg_nr fun_dep_vars cons_vars\n\t\t\t= (arg_nr, [], fun_dep_vars, cons_vars)\n\nwantInstanceDeclaration :: !ParseContext !Position !ParseState -> (!ParsedDefinition, !ParseState)\nwantInstanceDeclaration parseContext pi_pos pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tIdentToken class_name\n\t\t\t# (pi_class, pState) = stringToIdent class_name IC_Class pState\n\t\t\t-> want_instance_declaration class_name (Ident pi_class) parseContext pi_pos pState\n\t\tQualifiedIdentToken module_name class_name\n\t\t\t# (module_ident, pState) = stringToQualifiedModuleIdent module_name class_name IC_Class pState\n\t\t\t-> want_instance_declaration class_name (QualifiedIdent module_ident class_name) parseContext pi_pos pState\n\t\t_\n\t\t\t# pState = parseError \"String\" (Yes token) \"identifier\" pState\n\t\t\t# (pi_class, pState) = stringToIdent \"\" IC_Class pState\n\t\t\t-> want_instance_declaration \"\" (Ident pi_class) parseContext pi_pos pState\n\twhere\n\twant_instance_declaration class_name pi_class parseContext pi_pos pState\n\t\t# ((pi_types, pi_context), pState) = want_instance_type pState\n\t\t (pi_ident, pState) = stringToIdent class_name (IC_Instance pi_types) pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| isIclContext parseContext\n\t\t\t# pState = want_begin_group token pState\n\t\t\t (pi_members, pState) = wantDefinitions (SetInstanceDefsContext parseContext) pState\n\t\t\t pState = wantEndGroup \"instance\" pState\n\t\t\t= (PD_Instance {pim_pi = {pi_class = pi_class, pi_ident = pi_ident, pi_types = pi_types, pi_context = pi_context,\n\t\t\t\t\t\t\t\t\t pi_specials = SP_None, pi_pos = pi_pos},\n\t\t\t\t\t\t\tpim_members = pi_members}, pState)\n\t\t\/\/ otherwise \/\/ ~ (isIclContext parseContext)\n\t\t\t| token == CommaToken\n\t\t\t\t# (pi_types_and_contexts, pState)\t= want_instance_types pState\n\t\t\t\t (idents, pState)\t\t= seqList [stringToIdent class_name (IC_Instance type) \\\\ (type,context) <- pi_types_and_contexts] pState\n\t\t\t\t= (PD_Instances\n\t\t\t\t\t[ {\tpim_pi = { pi_class = pi_class, pi_ident = ident, pi_types = type, pi_context = context\n\t\t\t\t\t\t\t\t , pi_specials = SP_None, pi_pos = pi_pos},\n\t\t\t\t\t\tpim_members = [] } \n\t\t\t\t\t\\\\\t(type,context)\t<- [ (pi_types, pi_context) : pi_types_and_contexts ]\n\t\t\t\t\t&\tident\t\t\t<- [ pi_ident : idents ]\n\t\t\t\t\t]\n\t\t\t\t , pState\n\t\t\t\t )\n\t\t\t\/\/ otherwise \/\/ token <> CommaToken\n\t\t\t\t# (specials, pState) = optionalSpecials (tokenBack pState)\n\t\t\t\t# pim_pi = {pi_class = pi_class, pi_ident = pi_ident, pi_types = pi_types,\n\t\t\t\t\t\t\tpi_context = pi_context, pi_specials = specials, pi_pos = pi_pos}\n\t\t\t\t= want_optional_member_types pim_pi pState\n\n\twant_begin_group token pState \/\/ For JvG layout\n\t\t# \/\/ (token, pState) = nextToken TypeContext pState PK\n\t\t (token, pState)\n\t\t\t= case token of\n\t\t\t\tSemicolonToken\t->\tnextToken TypeContext pState\n\t\t\t\t_\t\t\t\t->\t(token, pState)\n\t\t= case token of\n\t\t\tWhereToken\t-> wantBeginGroup \"instance declaration\" pState\n\t\t\tCurlyOpenToken\n\t\t\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t\t\t| ss_useLayout\n\t\t\t\t\t-> parseError \"instance declaration\" (Yes token) \"where\" pState\n\t\t\t\t\t-> pState\n\t\t\t_\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t\t\t| ss_useLayout\n\t\t\t\t\t-> parseError \"instance declaration\" (Yes token) \"where\" pState\n\t\t\t\t\t-> parseError \"instance declaration\" (Yes token) \"where or {\" pState\n\n\twant_optional_member_types pim_pi pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t# (begin_members, pState) = begin_member_group token pState\n\t\t| begin_members\n\t\t\t# (instance_member_types, pState) = want_instance_type_definitions pim_pi.pi_types pState\n \t \t pState = wantEndGroup \"instance\" pState\n\t\t\t= (PD_Instance {pim_pi = pim_pi, pim_members = instance_member_types}, pState)\n\t\t\t# pState = wantEndOfDefinition \"instance declaration\" (tokenBack pState)\n\t\t\t= (PD_Instance {pim_pi = pim_pi, pim_members = []}, pState)\n\n\twant_instance_type pState\n\t\t# (pi_types, pState)\t= wantList \"instance types\" tryBrackType pState\n\t\t (pi_context, pState)\t= optionalContext pState\n\t\t= ((pi_types, pi_context), pState)\n\twant_instance_types pState\n\t\t# (type_and_context, pState) = want_instance_type pState\n\t\t (token, pState) = nextToken TypeContext pState\n\t\t| token == CommaToken\n\t\t\t# (types, pState) = want_instance_types pState\n\t\t\t= ([type_and_context:types], pState)\n\t\t\/\/ otherwise \/\/ token <> CommaToken\n\t\t\t= ([type_and_context], pState)\n\n\tbegin_member_group SemicolonToken pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == WhereToken\n\t\t\t= begin_member_group_where pState\n\t\t| token == CurlyOpenToken\n\t\t\t= begin_member_group_curly_open pState\n\t\t\t= (False, tokenBack pState)\n\tbegin_member_group token pState\n\t\t| token == WhereToken\n\t\t\t= begin_member_group_where pState\n\t\t| token == CurlyOpenToken\n\t\t\t= begin_member_group_curly_open pState\n\t\t\t= (False, pState)\n\n\tbegin_member_group_where pState\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == CurlyOpenToken\n\t\t\t| ss_useLayout\n\t\t\t\t= (True, parseError \"instance definition\" No \"No { in layout mode\" pState) \n\t\t\t\t= (True, pState)\n\t\t\t= (True, tokenBack pState)\n\n\tbegin_member_group_curly_open pState\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t| ss_useLayout\n\t\t\t= (True, parseError \"instance definition\" (Yes CurlyOpenToken) \"in layout mode the keyword where is\" pState) \n\t\t\t= (True, pState)\n\noptionalContext :: !ParseState -> ([TypeContext],ParseState)\noptionalContext pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == BarToken\n\t\t= want_contexts pState\n\t\t= ([], tokenBack pState)\n\noptional_constructor_context :: !ParseState -> ([TypeContext],ParseState)\noptional_constructor_context pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == AndToken\n\t\t= want_contexts pState\n\t\t= ([], tokenBack pState)\n\nwant_contexts :: ParseState -> ([TypeContext],ParseState)\nwant_contexts pState\n\t# (contexts, pState) = want_context pState\n\t (token, pState) = nextToken TypeContext pState\n\t| token == AndToken\n\t\t# (more_contexts, pState) = want_contexts pState\n\t\t= (contexts ++ more_contexts, pState)\n\t\t= (contexts, tokenBack pState)\nwhere\n\/*\t\t\t\n\twant_context pState\n\t\t# (class_names, pState) = wantSequence CommaToken TypeContext pState\n\t\t (types, pState)\t= wantList \"type arguments\" tryBrackType pState \/\/ tryBrackAType ??\n\t\t= build_contexts class_names types (length types) pState\n\twhere\n\t\tbuild_contexts [] types arity pState\n\t\t\t= ([], pState)\n\t\tbuild_contexts [class_ident : class_names] types arity pState\n\t\t\t# (contexts, pState) = build_contexts class_names types arity pState\n\t\t\t (class_ident, pState) = stringToIdent class_ident IC_Class pState\n\t\t\t tc_class = { glob_object = MakeDefinedSymbol class_ident NoIndex (length types), glob_module = NoIndex }\n\t\t\t= ([{ tc_class = tc_class, tc_types = types, tc_var = nilPtr } : contexts], pState)\n*\/\n\/**\/\n\twant_context pState \n\t\t# (tc_classes, pState) = wantSepList \"classes\" CommaToken TypeContext try_tc_class pState\n\t\t# (types, pState)\t= wantList \"type arguments\" tryBrackType pState \/\/ tryBrackAType ??\n\t\t# {ps_error} = pState\n\t\t#! ok = ps_error.pea_ok\n\t\t# pState = {pState & ps_error = ps_error}\n\t\t| ok\n\t\t\t= mapSt (build_context types (length types)) tc_classes pState\n\t\t\t= ([], pState)\n\t\n\ttry_tc_class pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t= case token of \n\t\t\tIdentToken name \n\t\t\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t\t\t-> case token of\n\t\t\t\t\tGenericOpenToken \n\t\t\t\t\t\t# (ident, pState) = stringToIdent name IC_Generic pState\t\t\t\n\t\t\t\t\t\t# (kind, pState) = wantKind pState\t\t\t\t\t\t \n\t\t\t \t\t\t# generic_global_ds = { glob_object = MakeDefinedSymbol ident NoIndex 1, glob_module = NoIndex }\n\t\t\t\t\t\t# class_global_ds = { glob_object = MakeDefinedSymbol {id_name=\"\",id_info=nilPtr} NoIndex 1, glob_module = NoIndex}\n\t\t\t\t\t\t\n\t\t\t\t\t\t# gen_type_context = \n\t\t\t\t\t\t\t{ gtc_generic = {glob_object = MakeDefinedSymbol ident NoIndex 1, glob_module = NoIndex}\n\t\t\t\t\t\t\t, gtc_kind = kind\n\t\t\t\t\t\t\t, gtc_class = {glob_object = MakeDefinedSymbol {id_name=\"\",id_info=nilPtr} NoIndex 1, glob_module = NoIndex}\n\t\t\t\t\t\t\t, gtc_generic_dict = {gi_module = NoIndex, gi_index = NoIndex}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t-> (True, TCGeneric gen_type_context, pState)\n\t\t\t\t\t_ \n\t\t\t\t\t\t# pState = tokenBack pState\n\t\t\t\t\t\t# (ident, pState) = stringToIdent name IC_Class pState\n\t\t\t \t\t\t# class_global_ds = { glob_object = MakeDefinedSymbol ident NoIndex (-1), glob_module = NoIndex }\n\t\t\t\t\t\t-> (True, TCClass class_global_ds, pState)\n\t\t\tQualifiedIdentToken module_name ident_name\n\t\t\t\t# (module_ident, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Class pState\n\t\t\t\t-> (True, TCQualifiedIdent module_ident ident_name, pState)\n\t\t\t_\n\t\t\t\t-> (False, abort \"no tc_class\", tokenBack pState)\n\t\n\tbuild_context types length_types (TCClass class_global_ds=:{glob_object}) pState\n\t\t# tc_class = TCClass {class_global_ds & glob_object = {glob_object & ds_arity = length_types}}\n\t\t= ({ tc_class = tc_class, tc_var = nilPtr, tc_types = types}, pState)\n\tbuild_context types length_types tc_class=:(TCQualifiedIdent module_name ident_name) pState\n\t\t= ({ tc_class = tc_class, tc_var = nilPtr, tc_types = types}, pState)\n\tbuild_context types 1 (TCGeneric gtc=:{gtc_generic=gtc_generic=:{glob_object}}) pState\n\t\t# gtc = { gtc & gtc_generic = {gtc_generic & glob_object = {glob_object & ds_arity = 1}}} \n\t\t= ({ tc_class = TCGeneric gtc, tc_var = nilPtr, tc_types = types }, pState)\n\tbuild_context types length_types tc_class=:(TCGeneric _) pState\n\t\t# pState = parseErrorSimple \"type context\" \"generic class can have only one class argument\" pState\t\t\t\t\t\n\t\t= (abort \"No TypeContext\", pState)\n\/**\/\t\t\t\t\t\t \noptionalCoercions :: !ParseState -> ([AttrInequality], ParseState)\noptionalCoercions pState \n\t# (token, pState) = nextToken TypeContext pState\n\t| token == CommaToken\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == SquareOpenToken\n\t\t\t# (inequals, pState) = want_inequalities pState\n\t\t\t= (inequals, wantToken FunctionContext \"coercions\" SquareCloseToken pState)\n\t\t\t= ([], parseError \"Function type: coersions\" (Yes token) \"[\" pState)\n\t\t= ([], tokenBack pState)\n\twhere\n\t\twant_inequalities pState\n\t\t\t# (token, pState) = nextToken TypeContext pState\n \t\t\t (_, inequals, pState) = want_attr_inequality token pState\n\t\t\t (token, pState) = nextToken TypeContext pState\n\t\t\t| token == CommaToken\n\t\t\t\t# (more_inequals, pState) = want_inequalities pState\n\t\t\t\t= (inequals ++ more_inequals, pState)\n\t\t\t\t= (inequals, tokenBack pState)\n\t\twant_attr_inequality (IdentToken var_name) pState\n\t\t\t| isLowerCaseName var_name\n\t\t\t\t# (off_ident, pState) = stringToIdent var_name IC_TypeAttr pState\n\t\t\t\t (token, pState) = nextToken TypeContext pState\n\t\t\t\t| token == LessThanOrEqualToken\n\t\t\t\t\t# (var_name, pState) = wantLowerCaseName \"attribute inequality\" pState\n\t\t\t\t\t (dem_ident, pState) = stringToIdent var_name IC_TypeAttr pState\n\t\t\t\t\t ai_demanded = makeAttributeVar dem_ident\n\t\t\t\t\t= (ai_demanded, [{ ai_demanded = ai_demanded, ai_offered = makeAttributeVar off_ident }], pState)\t\t\t\t\n\t\t\t\t\t# (ai_demanded, inequals, pState) = want_attr_inequality token pState\n\t\t\t\t\t= (ai_demanded, [{ ai_demanded = ai_demanded, ai_offered = makeAttributeVar off_ident } : inequals], pState)\n\t\twant_attr_inequality token pState\n\t\t\t# erroneous_attr_var = makeAttributeVar erroneousIdent\n\t\t\t= (\terroneous_attr_var\n\t\t\t , [{ ai_demanded = erroneous_attr_var, ai_offered = erroneous_attr_var }]\n\t\t\t , parseError \"Function type: optional coercions\" (Yes token) \"\" pState\n\t\t\t )\n\n\/* Generic definitions *\/\n\nwantGenericDefinition :: !ParseContext !Position !ParseState -> (!ParsedDefinition, !ParseState)\nwantGenericDefinition parseContext pos pState\n\t| pState.ps_flags bitand PS_SupportGenericsMask==0\n\t\t= (PD_Erroneous, parseErrorSimple \"generic definition\" \"to enable generics use the command line flag -generics\" pState)\n\t# (name, pState) = want_name pState\n\t| name == \"\" \n\t\t= (PD_Erroneous, pState)\n\t# (ident, pState) = stringToIdent name IC_Generic\/*IC_Class*\/ pState\n\t# (member_ident, pState) = stringToIdent name IC_Expression pState\n\t# (arg_vars, pState) = wantList \"generic variable(s)\" try_variable pState\n\t# (gen_deps, pState) = optionalDependencies pState\n\t# pState = wantToken TypeContext \"generic definition\" DoubleColonToken pState\n\t# (type, pState) = wantSymbolType pState\n\t# pState = wantEndOfDefinition \"generic definition\" pState\n\t# gen_def = \n\t\t{\tgen_ident = ident\n\t\t,\tgen_member_ident = member_ident \n\t\t,\tgen_type = type\n\t\t,\tgen_vars = arg_vars\n\t\t,\tgen_deps = gen_deps \n\t\t,\tgen_pos = pos\n\t\t,\tgen_info_ptr = nilPtr\n\t\t}\n\t= (PD_Generic gen_def, pState)\t\n\twhere\n\t\twant_name pState \n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= \tcase token of\n\t\t\t\tIdentToken name -> (name, pState)\n\t\t\t\t_ -> (\"\", parseError \"generic definition\" (Yes token) \"\" pState)\n\n\t\ttry_variable pState\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= tryTypeVarT token pState\n\n\t\toptionalDependencies :: !ParseState -> (![GenericDependency], !ParseState)\n\t\toptionalDependencies pState\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= case token of \n\t\t\t\tBarToken -> wantSepList \"generic dependencies\" CommaToken TypeContext wantDependency pState\n\t\t\t\t_ -> ([], tokenBack pState)\n\n\t\twantDependency :: !ParseState -> (Bool, GenericDependency, ParseState)\n\t\twantDependency pState \n\t\t\t# (ident, pState) = wantIdentOrQualifiedIdent pState\n\t\t\t# (vars, pState) = wantList \"generic dependency variable(s)\" try_variable pState\n\t\t\t= (True, {gd_ident = ident, gd_index = NoGlobalIndex, gd_vars = vars, gd_nums = repeatn (length vars) (-1)}, pState)\n\t\t\n\t\twantIdentOrQualifiedIdent pState\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= case token of\n\t\t\t\tIdentToken name \n\t\t\t\t\t# (ident, pState) = stringToIdent name IC_Generic pState\n\t\t\t\t\t= (Ident ident, pState)\n\t\t\t\tQualifiedIdentToken mod_name name \n\t\t\t\t\t# (mod_ident, pState) = stringToQualifiedModuleIdent mod_name name IC_Generic pState\n\t\t\t\t\t= (QualifiedIdent mod_ident name, pState)\n\t\t\t\t_ \n\t\t\t\t\t# (ident, pState) = stringToIdent \"\" IC_Generic pState\n\t\t\t\t\t= (Ident ident, parseError \"generic dependency\" (Yes token) \"\" pState)\n\nwantDeriveDefinition :: !ParseContext !Position !*ParseState -> (!ParsedDefinition, !*ParseState)\nwantDeriveDefinition parseContext pos pState\n\t| pState.ps_flags bitand PS_SupportGenericsMask==0\n\t\t= (PD_Erroneous, parseErrorSimple \"generic definition\" \"to enable generics use the command line flag -generics\" pState)\n\t# (token, pState) = nextToken TypeContext pState\n\t= case token of\n\t\tIdentToken name\n\t\t\t# (derive_defs, pState) = want_derive_types name pState\n\t\t\t-> (PD_Derive derive_defs, pState)\n\t\tClassToken\n\t\t\t# (class_name, pState) = want pState\n\t\t\t# (class_ident, pState) = stringToIdent class_name IC_Class pState\n\t\t\t# (derive_defs, pState) = want_derive_class_types class_ident pState\n\t\t\t-> (PD_Derive derive_defs, pState)\n\t\t_\n\t\t\t-> (PD_Erroneous, parseError \"Generic Definition\" (Yes token) \"\" pState)\nwhere\n\twant_name pState \n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t= \tcase token of\n\t\t\tIdentToken name -> (name, pState)\n\t\t\t_ -> (\"\", parseError \"Generic Definition\" (Yes token) \"\" pState)\n\n\twant_derive_types :: String !*ParseState -> ([GenericCaseDef], !*ParseState)\t\t\t\n\twant_derive_types name pState\n\t\t# (derive_def, token, pState) = want_derive_type name pState\n\t\t| token == CommaToken\n\t\t\t# (derive_defs, pState) = want_derive_types name pState\n\t\t\t= ([derive_def:derive_defs], pState)\n \t\t\t# pState = wantEndOfDefinition \"derive definition\" (tokenBack pState)\n\t\t\t= ([derive_def], pState)\n\n\twant_derive_type :: String !*ParseState -> (GenericCaseDef, !Token, !*ParseState)\t\t\t\n\twant_derive_type name pState\n\/\/\t\t# (type, pState) = wantType pState\n\t\t# (ok, {at_type=type}, pState) = trySimpleType TA_None pState\n\t\t# (ident, pState) = stringToIdent name (IC_GenericCase type) pState\n\t\t# (generic_ident, pState) = stringToIdent name IC_Generic pState\n\t\t# (type_cons, pState) = get_type_cons type pState\n\t\t# (token, pState) = nextToken GenericContext pState\n\t\t# (gcf_generic_info, generic_instance_deps, token, pState)\n\t\t\t= case token of\n\t\t\t\t\/\/ make sure no look ahead occurred in a non GenericContext (defines an offside)\n\t\t\t\tGenericOfToken\n\t\t\t\t\t-> case type_cons of\n\t\t\t\t\t\tTypeConsSymb {type_ident={id_name}}\n\t\t\t\t\t\t\t| id_name==\"OBJECT\" || id_name==\"CONS\" || id_name==\"RECORD\" || id_name==\"FIELD\"\n\t\t\t\t\t\t\t\t# (next_token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t\t-> case next_token of\n\t\t\t\t\t\t\t\t\tIdentToken name\n\t\t\t\t\t\t\t\t\t\t| isLowerCaseName name\n\t\t\t\t\t\t\t\t\t\t\t# (token, pState) = nextToken GenericContext pState\n\t\t\t\t\t\t\t\t\t\t\t# (generic_instance_deps, token, pState) = parse_optional_generic_instance_deps token pState\n\t\t\t\t\t\t\t\t\t\t\t-> (-1, generic_instance_deps, token, pState)\n\t\t\t\t\t\t\t\t\tCurlyOpenToken\n\t\t\t\t\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t\t\t\t-> case token of\n\t\t\t\t\t\t\t\t\t\t\tCurlyCloseToken\n\t\t\t\t\t\t\t\t\t\t\t\t# (token, pState) = nextToken GenericContext pState\n\t\t\t\t\t\t\t\t\t\t\t\t# (generic_instance_deps, token, pState) = parse_optional_generic_instance_deps token pState\n\t\t\t\t\t\t\t\t\t\t\t\t-> (0, generic_instance_deps, token, pState)\n\t\t\t\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t\t\t\t# (generic_info,pState) = parse_info_fields id_name token pState\n\t\t\t\t\t\t\t\t\t\t\t\t (token, pState) = nextToken GenericContext pState\n\t\t\t\t\t\t\t\t\t\t\t\t# (generic_instance_deps, token, pState) = parse_optional_generic_instance_deps token pState\n\t\t\t\t\t\t\t\t\t\t\t\t-> (generic_info,generic_instance_deps, token,pState)\n\t\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t\t# pState = parseError \"derive definition\" (Yes next_token) \"{ or lower case ident\" pState\n\t\t\t\t\t\t\t\t\t\t-> (0, AllGenericInstanceDependencies, token, pState)\n\t\t\t\t\t\t_\n\t\t\t\t\t\t\t-> (0, AllGenericInstanceDependencies, token, pState)\n\t\t\t\tGenericWithToken\n\t\t\t\t\t# (generic_instance_deps, token, pState) = parse_generic_instance_deps 0 0 pState\n\t\t\t\t\t-> (0, generic_instance_deps, token, pState)\n\t\t\t\t_\n\t\t\t\t\t-> (0, AllGenericInstanceDependencies, token, pState)\n\n\t\t# derive_def =\n\t\t\t{\tgc_pos = pos\n\t\t\t,\tgc_type = type\n\t\t\t,\tgc_type_cons = type_cons\n\t\t\t,\tgc_gcf = GCF ident {gcf_gident = generic_ident, gcf_generic = {gi_module=NoIndex,gi_index=NoIndex}, gcf_arity = 0,\n\t\t\t\t\t\t\t\t\tgcf_generic_info = gcf_generic_info, gcf_body = GCB_None, gcf_kind = KindError,\n\t\t\t\t\t\t\t\t\tgcf_generic_instance_deps = generic_instance_deps}\n\t\t\t}\n\t\t= (derive_def, token, pState) \n\n\twant_derive_class_types :: Ident !*ParseState -> ([GenericCaseDef], !*ParseState)\t\t\t\n\twant_derive_class_types class_ident pState\n\t\t# (derive_def, pState) = want_derive_class_type class_ident pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == CommaToken\n\t\t\t# (derive_defs, pState) = want_derive_class_types class_ident pState\n\t\t\t= ([derive_def:derive_defs], pState)\n \t\t\t# pState = wantEndOfDefinition \"derive definition\" (tokenBack pState)\n\t\t\t= ([derive_def], pState)\n\n\twant_derive_class_type :: Ident !*ParseState -> (GenericCaseDef, !*ParseState)\t\t\t\n\twant_derive_class_type class_ident pState\n\t\t# (type, pState) = wantType pState\n\t\t# (ident, pState) = stringToIdent class_ident.id_name (IC_GenericDeriveClass type) pState\n\t\t# (type_cons, pState) = get_type_cons type pState\n\t\t# derive_def = { gc_pos = pos, gc_type = type, gc_type_cons = type_cons,\n\t\t\t\t\t\t gc_gcf = GCFC ident class_ident}\n\t\t= (derive_def, pState)\n\n\tget_type_cons :: Type !*ParseState -> (TypeCons, !*ParseState)\t\n\tget_type_cons (TA type_symb []) pState \n\t\t= (TypeConsSymb type_symb, pState)\n\tget_type_cons (TB tb) pState \n\t\t= (TypeConsBasic tb, pState)\n\tget_type_cons TArrow pState\n\t\t= (TypeConsArrow, pState)\n\tget_type_cons (TV tv) pState\n\t\t| isDclContext parseContext\n\t\t\t= (TypeConsVar tv, pState)\t\t\t \n\tget_type_cons type pState \n\t\t# pState = parseError \"generic type\" No \" type constructor\" pState\n\t\t= (abort \"no TypeCons\", pState)\n\n\tparse_info_fields \"OBJECT\" token pState\n\t\t= parse_OBJECT_info_fields token 0 pState\n\tparse_info_fields \"CONS\" token pState\n\t\t= parse_CONS_info_fields token 0 pState\n\tparse_info_fields \"RECORD\" token pState\n\t\t= parse_RECORD_info_fields token 0 pState\n\tparse_info_fields \"FIELD\" token pState\n\t\t= parse_FIELD_info_fields token 0 pState\n\n\tparse_OBJECT_info_fields token=:(IdentToken name) generic_info pState\n\t\t# field_number=field_n_of_GenericTypeDefDescriptor name\n\t\t| field_number<0\n\t\t\t= (generic_info, parseError \"GenericTypeDefDescriptor\" (Yes token) \"field of GenericTypeDefDescriptor\" pState)\n\t\t# field_mask = 1<0)\n\t\t\t\t\t(parseErrorSimple \"GenericTypeDefDescriptor\" \"field already defined\" pState)\n\t\t\t\t\tpState\n\t\t generic_info = generic_info bitor field_mask\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tCommaToken\n\t\t\t\t# (token,pState) = nextToken FunctionContext pState\n\t\t\t\t-> parse_OBJECT_info_fields token generic_info pState\n\t\t\tCurlyCloseToken\n\t\t\t\t-> (generic_info,pState)\n\t\t\t_\n\t\t\t\t-> (generic_info, parseError \"GenericTypeDefDescriptor record\" (Yes token) \", or }\" pState)\n\tparse_OBJECT_info_fields token generic_info pState\n\t\t= (generic_info, parseError \"GenericTypeDefDescriptor record\" (Yes token) \"field name\" pState)\n\n\tparse_CONS_info_fields token=:(IdentToken name) generic_info pState\n\t\t# field_number=field_n_of_GenericConsDescriptor name\n\t\t| field_number<0\n\t\t\t= (generic_info, parseError \"GenericConsDescriptor\" (Yes token) \"field of GenericConsDescriptor\" pState)\n\t\t# field_mask = 1<0)\n\t\t\t\t\t(parseErrorSimple \"GenericConsDescriptor\" \"field already defined\" pState)\n\t\t\t\t\tpState\n\t\t generic_info = generic_info bitor field_mask\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tCommaToken\n\t\t\t\t# (token,pState) = nextToken FunctionContext pState\n\t\t\t\t-> parse_CONS_info_fields token generic_info pState\n\t\t\tCurlyCloseToken\n\t\t\t\t-> (generic_info,pState)\n\t\t\t_\n\t\t\t\t-> (generic_info, parseError \"GenericConsDescriptor record\" (Yes token) \", or }\" pState)\n\tparse_CONS_info_fields token generic_info pState\n\t\t= (generic_info, parseError \"GenericConsDescriptor record\" (Yes token) \"field name\" pState)\n\n\tparse_RECORD_info_fields token=:(IdentToken name) generic_info pState\n\t\t# field_number=field_n_of_GenericRecordDescriptor name\n\t\t| field_number<0\n\t\t\t= (generic_info, parseError \"GenericRecordDescriptor\" (Yes token) \"field of GenericRecordDescriptor\" pState)\n\t\t# field_mask = 1<0)\n\t\t\t\t\t(parseErrorSimple \"GenericRecordDescriptor\" \"field already defined\" pState)\n\t\t\t\t\tpState\n\t\t generic_info = generic_info bitor field_mask\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tCommaToken\n\t\t\t\t# (token,pState) = nextToken FunctionContext pState\n\t\t\t\t-> parse_RECORD_info_fields token generic_info pState\n\t\t\tCurlyCloseToken\n\t\t\t\t-> (generic_info,pState)\n\t\t\t_\n\t\t\t\t-> (generic_info, parseError \"GenericRecordDescriptor record\" (Yes token) \", or }\" pState)\n\tparse_RECORD_info_fields token generic_info pState\n\t\t= (generic_info, parseError \"GenericRecordDescriptor record\" (Yes token) \"field name\" pState)\n\n\tparse_FIELD_info_fields token=:(IdentToken name) generic_info pState\n\t\t# field_number=field_n_of_GenericFieldDescriptor name\n\t\t| field_number<0\n\t\t\t= (generic_info, parseError \"GenericFieldDescriptor\" (Yes token) \"field of GenericFieldDescriptor\" pState)\n\t\t# field_mask = 1<0)\n\t\t\t\t\t(parseErrorSimple \"GenericFieldDescriptor\" \"field already defined\" pState)\n\t\t\t\t\tpState\n\t\t generic_info = generic_info bitor field_mask\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tCommaToken\n\t\t\t\t# (token,pState) = nextToken FunctionContext pState\n\t\t\t\t-> parse_FIELD_info_fields token generic_info pState\n\t\t\tCurlyCloseToken\n\t\t\t\t-> (generic_info,pState)\n\t\t\t_\n\t\t\t\t-> (generic_info, parseError \"GenericFieldDescriptor record\" (Yes token) \", or }\" pState)\n\tparse_FIELD_info_fields token generic_info pState\n\t\t= (generic_info, parseError \"GenericFieldDescriptor record\" (Yes token) \"field name\" pState)\n\n\tparse_optional_generic_instance_deps GenericWithToken pState\n\t\t= parse_generic_instance_deps 0 0 pState\n\tparse_optional_generic_instance_deps token pState\n\t\t= (AllGenericInstanceDependencies, token, pState)\n\n\tparse_generic_instance_deps n_deps deps pState\n\t\t# (token, pState) = nextToken GenericContext pState\n\t\t= case token of\n\t\t\tWildCardToken\n\t\t\t\t-> parse_generic_instance_deps (n_deps+1) deps pState\n\t\t\tIdentToken name\n\t\t\t | isLowerCaseName name\n\t\t\t\t-> parse_generic_instance_deps (n_deps+1) (deps bitor (1< (GenericInstanceDependencies n_deps deps, token, pState)\n\n\/*\n\tType definitions\n*\/\n\nwantTypeVar :: ! ParseState -> (!TypeVar, !ParseState)\nwantTypeVar pState\n\t# (succ, type_var, pState) = tryTypeVar pState\n\t| succ\n\t\t= (type_var, pState)\n\t\t= wantTypeVarError pState\n\nwantTypeVarT :: !Token !ParseState -> (!TypeVar, !ParseState)\nwantTypeVarT token pState\n\t# (succ, type_var, pState) = tryTypeVarT token pState\n\t| succ\n\t\t= (type_var, pState)\n\t\t= wantTypeVarError pState\n\nwantTypeVarError pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= (MakeTypeVar erroneousIdent, parseError \"Type Variable\" (Yes token) \"type variable\" pState)\n\ntryAttributedTypeVar :: !ParseState -> (!Bool, ATypeVar, !ParseState)\ntryAttributedTypeVar pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| is_type_arg_token token\n\t\t# (aOrA, attr, pState)\t= warnAnnotAndOptionalAttr (tokenBack pState)\n\t (succ, type_var, pState)\t\t= tryTypeVar pState\n\t | succ\n\t\t\t= (True, { atv_attribute = attr, atv_variable = type_var }, pState)\n\t\t| aOrA \/\/ annot <> AN_None || attr <> TA_None\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= (False, no_type_var, parseError \"Attributed type var\" (Yes token) \"type variabele after annotation or attribute\" pState)\n\t\t\/\/ otherwise\n\t \t= (False, no_type_var, tokenBack pState)\n\t\/\/ otherwise\n\t\t= (False, no_type_var, tokenBack pState)\nwhere\t\n\tis_type_arg_token (IdentToken t)\t= isLowerCaseName t\n\tis_type_arg_token DotToken \t= True\n\tis_type_arg_token AsteriskToken \t= True\n\tis_type_arg_token t \t= False\n\t\n\tno_type_var = abort \"tryAttributedTypeVar: No type var\"\n\nwantTypeDef :: !ParseContext !Position !ParseState -> (ParsedDefinition, !ParseState)\nwantTypeDef parseContext pos pState\n\t# (type_lhs, annot, pState)\t= want_type_lhs pos pState\n\t (token, pState)\t\t\t= nextToken TypeContext pState\n\t (def, pState)\t\t\t\t= want_type_rhs token parseContext type_lhs annot pState\n \t pState\t\t\t\t\t= wantEndOfDefinition \"type definition (6)\" pState\n \t= (def, pState)\nwhere\n\twant_type_lhs :: !Position !ParseState -> (!ParsedTypeDef, !Annotation, !ParseState)\n\twant_type_lhs pos pState\n\t\t# (_, annot, attr, pState)\t= optionalAnnotAndAttr pState\n\t\t (name, pState)\t\t\t= wantConstructorName \"Type name\" pState\n\t\t (ident, pState)\t\t\t= stringToIdent name IC_Type pState\n\t\t (args, pState)\t\t\t= parseList tryAttributedTypeVar pState\n\t\t= (MakeTypeDef ident args (ConsList []) attr pos, annot, pState)\n\n\twant_type_rhs :: !Token !ParseContext !ParsedTypeDef !Annotation !ParseState -> (ParsedDefinition, !ParseState)\n\twant_type_rhs EqualToken parseContext td=:{td_ident,td_attribute} annot pState\n\t\t# name\t\t\t\t\t= td_ident.id_name\n\t\t pState\t\t\t\t= verify_annot_attr annot td_attribute name pState\n\t\t (exi_vars, pState)\t= optionalExistentialQuantifiedVariables pState\n\t\t (token, pState)\t\t= nextToken GeneralContext pState \/\/ should be TypeContext\n\t\t= case token of\n\t\t\tCurlyOpenToken\n \t\t\t\t-> want_record_type_rhs name False exi_vars pState\n \t\t\tExclamationToken\n\t\t\t \t# (token, pState) = nextToken TypeContext pState\n \t\t\t\t| token==CurlyOpenToken\n \t\t\t\t\t-> want_record_type_rhs name True exi_vars pState\n\t \t\t \t\t->\t(PD_Type td, parseError \"Record type\" No (\"after ! in definition of record type \"+name+\" { \") pState)\n\t\t\t_\n\t\t\t\t# (condefs, extensible_algebraic_type, pState) = want_constructor_list exi_vars token pState\n\t\t\t\t# td & td_rhs = if extensible_algebraic_type (ExtensibleConses condefs) (ConsList condefs)\n\t\t\t\t| annot == AN_None\n\t \t\t \t\t->\t(PD_Type td, pState)\n\t\t\t\t\t->\t(PD_Type td, parseError \"Algebraic type\" No (\"No lhs strictness annotation for the algebraic type \"+name) pState)\n\twhere\n\t\twant_record_type_rhs name is_boxed_record exi_vars pState\n\t\t\t#\t(fields, pState)\t\t\t= wantFields td_ident pState\n\t\t\t\tpState\t\t\t\t\t\t= wantToken TypeContext \"record type def\" CurlyCloseToken pState\n\t\t\t \t(rec_cons_ident, pState)\t= stringToIdent (\"_\" + name) IC_Expression pState\n\t\t\t=\t(PD_Type { td & td_rhs = SelectorList rec_cons_ident exi_vars is_boxed_record fields }, pState)\n\n\twant_type_rhs ColonDefinesToken parseContext td=:{td_attribute} annot pState \/\/ type synonym\n\t\t# name\t\t\t\t= td.td_ident.id_name\n\t\t pState\t\t\t= verify_annot_attr annot td_attribute name pState\n\t\t (atype, pState)\t= want pState \/\/ Atype\n\t\t td\t\t\t\t= {td & td_rhs = TypeSpec atype}\n\t\t| annot == AN_None\n\t\t\t= (PD_Type td, pState)\n\t\t\t= (PD_Type td, parseError \"Type synonym\" No (\"No lhs strictness annotation for the type synonym \"+name) pState)\n\n\twant_type_rhs DefinesColonToken parseContext td=:{td_ident,td_attribute} annot pState\n\t\t# name\t\t\t\t\t= td_ident.id_name\n\t\t pState\t\t\t\t= verify_annot_attr annot td_attribute name pState\n\t\t (exi_vars, pState)\t= optionalExistentialQuantifiedVariables pState\n\t\t (token, pState)\t\t= nextToken GeneralContext pState\n\t\t (condef, pState)\t\t= want_newtype_constructor exi_vars token pState\n\t\t td\t\t\t\t\t= { td & td_rhs = NewTypeCons condef }\n\t\t| annot == AN_None\n\t \t\t= (PD_Type td, pState)\n\t \t\t= (PD_Type td, parseError \"New type\" No (\"No lhs strictness annotation for the new type \"+name) pState)\n\n\twant_type_rhs token=:OpenToken parseContext td=:{td_attribute} annot pState\n\t\t| isIclContext parseContext\n\t\t\t= (PD_Erroneous, parseError \"type RHS\" (Yes token) \"type definition\" pState)\n\t\t# pState = wantToken TypeContext \"Abstract type synonym\" ColonDefinesToken pState\t\t\t\n\t\t# name\t\t\t\t= td.td_ident.id_name\n\t\t (atype, pState)\t= want pState \/\/ Atype\n\t\t# (td_attribute, properties) = determine_properties annot td_attribute\n\t\t td\t\t\t\t= {td & td_rhs = AbstractTypeSpec properties atype, td_attribute=td_attribute}\n\t\t# pState = wantToken TypeContext \"Abstract type synonym\" CloseToken pState\n\t\t| td_attribute == TA_Anonymous || td_attribute == TA_Unique || td_attribute == TA_None\n\t\t\t= (PD_Type td, pState)\n\t\t\t= (PD_Type td, parseError \"abstract type\" No (\"type attribute \"+toString td_attribute+\" for abstract type \"+name+\" is not\") (tokenBack pState))\n\n\twant_type_rhs BarToken parseContext td=:{td_ident,td_attribute} annot pState\n\t\t# name\t\t\t\t\t= td_ident.id_name\n\t\t pState\t\t\t\t= verify_annot_attr annot td_attribute name pState\n\t\t (exi_vars, pState)\t= optionalExistentialQuantifiedVariables pState\n\t\t (token, pState)\t\t= nextToken GeneralContext pState \/\/ should be TypeContext\n\t\t (condefs, pState)\t\t= want_more_constructors exi_vars token pState\n\t\t (file_name, pState) = getFilename pState\n\t\t module_name = file_name % (0,size file_name-4)\n\t\t (type_ext_ident, pState) = stringToIdent name (IC_TypeExtension module_name) pState\n\t\t td & td_rhs\t\t\t= MoreConses type_ext_ident condefs\n\t\t| annot == AN_None\n\t \t\t= (PD_Type td, pState)\n\t \t\t= (PD_Type td, parseError \"Algebraic type\" No (\"No lhs strictness annotation for the algebraic type \"+name) pState)\n\n\twant_type_rhs token parseContext td=:{td_attribute} annot pState\n\t\t| isIclContext parseContext\n\t\t\t= (PD_Erroneous, parseError \"type RHS\" (Yes token) \"type definition\" pState)\n\t\t\t| td_attribute == TA_Anonymous || td_attribute == TA_Unique || td_attribute == TA_None\n\t\t\t\t# (td_attribute, properties) = determine_properties annot td_attribute\n\t\t\t\t# td = { td & td_attribute = td_attribute, td_rhs = EmptyRhs properties}\n\t\t\t\t= (PD_Type td, tokenBack pState)\n\t\t\t\t# name = td.td_ident.id_name\n\t\t\t\t= (PD_Type { td & td_rhs = EmptyRhs cAllBitsClear}, parseError \"abstract type\" No (\"type attribute \"+toString td_attribute+\" for abstract type \"+name+\" is not\") (tokenBack pState))\n\n\tverify_annot_attr :: !Annotation !TypeAttribute !String !ParseState -> ParseState\n\tverify_annot_attr annot attr name pState\n\t\t| annot <> AN_None\n\t\t\t= parseError \"type definition\" No (\"No annotation, \"+toString annot+\", in the lhs of type \"+name) pState\n\t\t| attr == TA_None || attr == TA_Unique\n\t\t\t= pState\n\t\t\t= parseError \"type definition\" No (\"No attribute, \"+toString attr+\", in the lhs of type \"+name) pState\n\n\tdetermine_properties :: !Annotation !TypeAttribute -> (!TypeAttribute, !BITVECT)\n\tdetermine_properties annot attr\n\t\t| annot == AN_Strict\n\t\t\t| attr == TA_Anonymous\n\t\t\t\t= (TA_None, cIsHyperStrict)\n\t\t\t\t= (attr, cIsHyperStrict bitor cIsNonCoercible)\n\t\t| attr == TA_Anonymous\n\t\t\t= (TA_None, cAllBitsClear)\n\t\t\t= (attr, cIsNonCoercible)\n\n\twant_constructor_list :: ![ATypeVar] !Token !ParseState -> (![ParsedConstructor],!Bool,!ParseState)\n\twant_constructor_list exi_vars DotDotToken pState\n\t\t= ([], True, pState)\n\twant_constructor_list exi_vars token pState\n\t\t# (cons,pState) = want_constructor exi_vars token pState\n\t\t (token, pState) = nextToken TypeContext pState\n\t\t| token == BarToken\n\t\t\t# (exi_vars, pState) = optionalExistentialQuantifiedVariables pState\n\t\t\t (token, pState) = nextToken GeneralContext pState\n\t\t\t (cons_list, extensible_algebraic_type, pState) = want_constructor_list exi_vars token pState\n\t\t\t= ([cons : cons_list], extensible_algebraic_type, pState)\n\t\t\t= ([cons], False, tokenBack pState)\n\n\twant_more_constructors :: ![ATypeVar] !Token !ParseState -> (![ParsedConstructor],!ParseState)\n\twant_more_constructors exi_vars token pState\n\t\t# (cons,pState) = want_constructor exi_vars token pState\n\t\t (token, pState) = nextToken TypeContext pState\n\t\t| token == BarToken\n\t\t\t# (exi_vars, pState) = optionalExistentialQuantifiedVariables pState\n\t\t\t (token, pState) = nextToken GeneralContext pState\n\t\t\t (cons_list, pState) = want_more_constructors exi_vars token pState\n\t\t\t= ([cons : cons_list], pState)\n\t\t\t= ([cons], tokenBack pState)\n\n\twant_constructor :: ![ATypeVar] !Token !ParseState -> (.ParsedConstructor,!ParseState)\n\twant_constructor exi_vars token pState\n\t\t# token = basic_type_to_constructor token\n\t\t# (pc_cons_ident, pc_cons_prio, pc_cons_pos, pState) = want_cons_name_and_prio token pState\n\t\t (pc_arg_types, pState) = parseList tryBrackSAType pState\n\t\t pState = case pc_cons_prio of\n\t\t\t\t\t\tNoPrio\n\t\t\t\t\t\t\t-> pState\n\t\t\t\t\t\tPrio _ _\n\t\t\t\t\t\t\t-> case pc_arg_types of\n\t\t\t\t\t\t\t\t[_,_]\n\t\t\t\t\t\t\t\t\t-> pState\n\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t-> parseErrorSimple pc_cons_ident.id_name \"arity of an infix constructor should be 2\" pState\n\t\t (pc_context,pState) = optional_constructor_context pState\n\t\t cons = {\tpc_cons_ident = pc_cons_ident, pc_arg_types = atypes_from_satypes pc_arg_types, pc_args_strictness=strictness_from_satypes pc_arg_types,\n\t\t\t\t\tpc_context = pc_context, pc_cons_arity = length pc_arg_types, pc_cons_prio = pc_cons_prio, pc_exi_vars = exi_vars, pc_cons_pos = pc_cons_pos}\n\t\t= (cons,pState)\n\n\twant_newtype_constructor :: ![ATypeVar] !Token !ParseState -> (.ParsedConstructor,!ParseState)\n\twant_newtype_constructor exi_vars token pState\n\t\t# token = basic_type_to_constructor token\n\t\t (pc_cons_ident, pc_cons_prio, pc_cons_pos, pState) = want_cons_name_and_prio token pState\n\t\t (succ, pc_arg_type, pState) = trySimpleType TA_Anonymous pState\n\t\t cons = {\tpc_cons_ident = pc_cons_ident, pc_arg_types = [pc_arg_type], pc_args_strictness = NotStrict,\n\t\t \t\t\tpc_context = [], pc_cons_arity = 1, pc_cons_prio = pc_cons_prio, pc_exi_vars = exi_vars, pc_cons_pos = pc_cons_pos}\n\t\t| succ\n\t\t\t= (cons,pState)\n\t\t\t= (cons,parseError \"newtype definition\" No \"type\" pState)\n\n\twant_cons_name_and_prio :: !Token !ParseState -> (Ident, !Priority, !Position, !ParseState)\n\twant_cons_name_and_prio tok=:(IdentToken name) pState\n\t\t# (ident, pState) = stringToIdent name IC_Expression pState\n\t \t (fname, linenr, pState) = getFileAndLineNr pState\n\t \t (token, pState) = nextToken TypeContext pState\n\t \t (prio, pState) = optionalPriority cIsNotInfix token pState\n\t \t| isLowerCaseName name\n\t\t\t= (ident, prio, LinePos fname linenr, parseError \"Algebraic or new type: constructor definitions\" (Yes tok) \"constructor name\" pState)\n\t\t\t= (ident, prio, LinePos fname linenr, pState)\n\twant_cons_name_and_prio OpenToken pState\n\t\t# (name, pState) = wantConstructorName \"infix constructor\" pState\n\t \t (fname, linenr, pState) = getFileAndLineNr pState\n\t\t (ident, pState) = stringToIdent name IC_Expression pState\n\t (token, pState) = nextToken TypeContext (wantToken TypeContext \"type: constructor and prio\" CloseToken pState)\n\t\t (prio, pState) = optionalPriority cIsInfix token pState\n\t\t= (ident, prio, LinePos fname linenr, pState)\n\twant_cons_name_and_prio DotToken pState\n\t\t# (token,pState)\t= nextToken GeneralContext pState\n\t\t= case token of\n\t\t\tIdentToken name\n\t\t\t\t| isFunnyIdName name -> want_cons_name_and_prio (IdentToken (\".\"+name)) pState\n\t\t\t_\t-> (erroneousIdent, NoPrio, NoPos, parseError \"Algebraic or new type: constructor list\" (Yes DotToken) \"constructor name\" (tokenBack pState))\n\twant_cons_name_and_prio token pState\n\t\t= (erroneousIdent, NoPrio, NoPos, parseError \"Algebraic or new type: constructor list\" (Yes token) \"constructor name\" pState)\n\n\tbasic_type_to_constructor IntTypeToken\t\t= IdentToken \"Int\"\n\tbasic_type_to_constructor CharTypeToken\t\t= IdentToken \"Char\"\n\tbasic_type_to_constructor RealTypeToken\t\t= IdentToken \"Real\"\n\tbasic_type_to_constructor BoolTypeToken\t\t= IdentToken \"Bool\"\n\tbasic_type_to_constructor StringTypeToken\t= IdentToken \"String\"\n\tbasic_type_to_constructor FileTypeToken\t\t= IdentToken \"File\"\n\tbasic_type_to_constructor WorldTypeToken\t= IdentToken \"World\"\n\tbasic_type_to_constructor DynamicTypeToken\t= IdentToken \"Dynamic\"\n\tbasic_type_to_constructor token\t\t\t\t= token\n\nmakeAttributeVar name :== { av_ident = name, av_info_ptr = nilPtr }\n\noptionalAnnot :: !ParseState -> (!Bool,!Annotation, !ParseState)\noptionalAnnot pState\n \t# (token, pState) = nextToken TypeContext pState\n \t| token == ExclamationToken\n\t \t# (token, pState) = nextToken TypeContext pState\n\/\/ JVG added for strict lists:\n\t\t| token==SquareCloseToken\n\t\t\t= (False,AN_None,tokenBack (tokenBack pState))\n\t\t= (True, AN_Strict, tokenBack pState)\n\t| otherwise \/\/ token <> ExclamationToken\n\t\t= (False, AN_None, tokenBack pState)\n\noptionalAnnotWithPosition :: !ParseState -> (!Bool,!AnnotationWithPosition, !ParseState)\noptionalAnnotWithPosition pState\n \t# (token, pState) = nextToken TypeContext pState\n \t| token == ExclamationToken\n\t \t# (token, pState) = nextToken TypeContext pState\n\/\/ JVG added for strict lists:\n\t\t| token==SquareCloseToken\n\t\t\t= (False,NoAnnot,tokenBack (tokenBack pState))\n\t\t# (position,pState) = getPosition pState\n\t\t= (True, StrictAnnotWithPosition position, tokenBack pState)\n\t| otherwise \/\/ token <> ExclamationToken\n\t\t= (False, NoAnnot, tokenBack pState)\n\nwarnAnnotAndOptionalAttr :: !ParseState -> (!Bool, !TypeAttribute, !ParseState)\nwarnAnnotAndOptionalAttr pState\n \t# (token, pState) = nextToken TypeContext pState\n \t| token == ExclamationToken\n\t \t# (token, pState) = nextToken TypeContext pState\n\/\/ JVG added for strict lists:\n\t\t| token==SquareCloseToken\n\t\t\t= (False,TA_None,tokenBack (tokenBack pState))\n\t\t# (_ , attr, pState) = tryAttribute token pState\n\t\t# pState = parseWarning \"\" \"! ignored\" pState\n\t\t= (True, attr, pState)\n\t| otherwise \/\/ token <> ExclamationToken\n\t\t= tryAttribute token pState\n\noptionalAnnotAndAttr :: !ParseState -> (!Bool, !Annotation, !TypeAttribute, !ParseState)\noptionalAnnotAndAttr pState\n \t# (token, pState) = nextToken TypeContext pState\n \t| token == ExclamationToken\n\t \t# (token, pState) = nextToken TypeContext pState\n\/\/ JVG added for strict lists:\n\t\t| token==SquareCloseToken\n\t\t\t= (False,AN_None,TA_None,tokenBack (tokenBack pState))\n\t\t# (_ , attr, pState) = tryAttribute token pState\n\t\t= (True, AN_Strict, attr, pState)\n\t| otherwise \/\/ token <> ExclamationToken\n\t\t# (succ, attr, pState) = tryAttribute token pState\n\t\t= (succ, AN_None, attr, pState)\n\noptionalAnnotAndAttrWithPosition :: !ParseState -> (!Bool, !AnnotationWithPosition, !TypeAttribute, !ParseState)\noptionalAnnotAndAttrWithPosition pState\n \t# (token, pState) = nextToken TypeContext pState\n \t| token == ExclamationToken\n\t \t# (token, pState) = nextToken TypeContext pState\n\/\/ JVG added for strict lists:\n\t\t| token==SquareCloseToken\n\t\t\t= (False,NoAnnot,TA_None,tokenBack (tokenBack pState))\n\t\t# (position,pState) = getPosition pState\n\t\t# (_ , attr, pState) = tryAttribute token pState\n\t\t= (True, StrictAnnotWithPosition position, attr, pState)\n\t| otherwise \/\/ token <> ExclamationToken\n\t\t# (succ, attr, pState) = tryAttribute token pState\n\t\t= (succ, NoAnnot, attr, pState)\n\n\/\/ Sjaak 210801 ...\n\t\t \ntryAttribute :: !Token !ParseState -> (!Bool, !TypeAttribute, !ParseState)\ntryAttribute DotToken pState = (True, TA_Anonymous, pState)\ntryAttribute AsteriskToken pState = (True, TA_Unique, pState)\ntryAttribute (IdentToken name) pState\n\t| isLowerCaseName name\n \t# (token, pState) = nextToken TypeContext pState\n\t| ColonToken == token\n\t\t# (ident, pState) = stringToIdent name IC_TypeAttr pState\n\t\t= (True, TA_Var (makeAttributeVar ident), pState)\n\t\t= (False, TA_None, tokenBack (tokenBack pState))\ntryAttribute _\t pState = (False, TA_None, tokenBack pState)\n \n\/\/ ... Sjaak\n\ncIsInfix\t:== True\ncIsNotInfix\t:== False\n\nwantFields :: !Ident !*ParseState -> (![ParsedSelector], !*ParseState)\nwantFields record_type pState\n\t# (field, pState) = want_field record_type pState\n\t (token, pState) = nextToken TypeContext pState\n\t| token == CommaToken\n\t\t# (fields, pState) = wantFields record_type pState\n\t\t= ([field : fields], pState)\n\t\t= ([field], tokenBack pState)\n\twhere\n\t\twant_field :: !Ident !*ParseState -> *(!ParsedSelector, !*ParseState)\n\t\twant_field record_type pState\n\t\t\t# (field_name, pState) \t\t\t= wantLowerCaseName \"record field\" pState\n\t\t\t (fname, linenr, pState)\t\t= getFileAndLineNr pState\n\t\t\t (ps_field_ident, pState) \t\t= stringToIdent field_name (IC_Field record_type) pState\n\t\t\t (ps_selector_ident, pState) \t= stringToIdent field_name IC_Selector pState\n\t\t\t (ps_field_var, pState) \t\t= stringToIdent field_name IC_Expression pState\n\t\t\t pState \t\t\t\t= wantToken TypeContext \"record field\" DoubleColonToken pState\n\/\/\t\t\t (ps_field_type, pState) \t\t= want pState \/\/ wantAType\n\t\t\t (annotation,ps_field_type, pState) = wantAnnotatedAType pState\n\t\t\t= ({ ps_field_ident = ps_field_ident, ps_selector_ident = ps_selector_ident, ps_field_type = ps_field_type,\n\t\t\t\t\tps_field_annotation = annotation,\n\t\t\t\t\tps_field_var = ps_field_var, ps_field_pos = LinePos fname linenr}, pState)\n\n:: SAType = {s_annotation::!Annotation,s_type::!AType}\n\n:: SATypeWithPosition = {sp_annotation::!AnnotationWithPosition,sp_type::!AType}\n\natypes_from_sptypes_and_warn_if_strict :: ![SATypeWithPosition] !ParseState -> (![AType],!ParseState)\natypes_from_sptypes_and_warn_if_strict [] pState\n\t= ([],pState)\natypes_from_sptypes_and_warn_if_strict [{sp_type,sp_annotation}:types] pState\n\t# pState = warnIfStrictAnnot sp_annotation pState\n\t# (atypes,pState) = atypes_from_sptypes_and_warn_if_strict types pState\n\t= ([sp_type:atypes],pState)\n\natypes_from_sptypes :: ![SATypeWithPosition] -> [AType]\natypes_from_sptypes []\n\t= []\natypes_from_sptypes [{sp_type}:types]\n\t= [sp_type:atypes_from_sptypes types]\n\natypes_from_satypes :: ![SAType] -> [AType]\natypes_from_satypes []\n\t= []\natypes_from_satypes [{s_type}:types]\n\t= [s_type:atypes_from_satypes types]\n\nstrictness_from_satypes types\n\t= add_strictness_for_arguments types 0 0 NotStrict\nwhere \n\tadd_strictness_for_arguments :: ![SAType] !Int !Int !StrictnessList -> StrictnessList\n\tadd_strictness_for_arguments [] strictness_index strictness strictness_list\n\t\t| strictness==0\n\t\t\t= strictness_list\n\t\t\t= append_strictness strictness strictness_list\n\tadd_strictness_for_arguments [{s_annotation=AN_Strict}:types] strictness_index strictness strictness_list\n\t\t# (strictness_index,strictness,strictness_list) = add_next_strict strictness_index strictness strictness_list\n\t\t= add_strictness_for_arguments types strictness_index strictness strictness_list\n\tadd_strictness_for_arguments [{s_annotation=AN_None}:types] strictness_index strictness strictness_list\n\t\t# (strictness_index,strictness,strictness_list) = add_next_not_strict strictness_index strictness strictness_list\n\t\t= add_strictness_for_arguments types strictness_index strictness strictness_list\n\nstrictness_from_sptypes types\n\t= add_strictness_for_arguments types 0 0 NotStrict\nwhere \n\tadd_strictness_for_arguments :: ![SATypeWithPosition] !Int !Int !StrictnessList -> StrictnessList\n\tadd_strictness_for_arguments [] strictness_index strictness strictness_list\n\t\t| strictness==0\n\t\t\t= strictness_list\n\t\t\t= append_strictness strictness strictness_list\n\tadd_strictness_for_arguments [{sp_annotation=StrictAnnotWithPosition _}:types] strictness_index strictness strictness_list\n\t\t# (strictness_index,strictness,strictness_list) = add_next_strict strictness_index strictness strictness_list\n\t\t= add_strictness_for_arguments types strictness_index strictness strictness_list\n\tadd_strictness_for_arguments [{sp_annotation=NoAnnot}:types] strictness_index strictness strictness_list\n\t\t# (strictness_index,strictness,strictness_list) = add_next_not_strict strictness_index strictness strictness_list\n\t\t= add_strictness_for_arguments types strictness_index strictness strictness_list\n\nmakeSymbolType args result context attr_env :==\n\t{ st_vars = [], st_args = atypes_from_sptypes args, st_args_strictness = strictness_from_sptypes args,st_arity = length args, st_result = result,\n\t st_context = context, st_attr_env = attr_env, st_attr_vars = [] }\n\nwantSymbolType pState\n\/\/\t# (vars , pState) = optionalUniversalQuantifiedVariables pState \/\/ PK\n\t# (types, pState) = parseList tryBrackSATypeWithPosition pState\n\t (token, pState) = nextToken TypeContext pState\n\t= want_rest_of_symbol_type token types pState\nwhere\n\twant_rest_of_symbol_type :: !Token ![SATypeWithPosition] !ParseState -> (!SymbolType, !ParseState)\n\twant_rest_of_symbol_type ArrowToken types pState\n\t\t# pState\t\t\t\t= case types of\n\t\t\t\t\t\t\t\t\t[]\t-> parseWarning \"want SymbolType\" \"types before -> expected\" pState\n\t\t\t\t\t\t\t\t\t_\t-> pState\n\t\t# (type, pState)\t\t= want pState\n\t\t (context, pState)\t\t= optionalContext pState\n\t\t (attr_env, pState)\t= optionalCoercions pState\n\t\t= (makeSymbolType types type context attr_env, pState)\n\twant_rest_of_symbol_type token [] pState\n\t\t= (makeSymbolType [] (MakeAttributedType TE) [] [], parseError \"symbol type\" (Yes token) \"type\" pState)\n\twant_rest_of_symbol_type token [{sp_type=type,sp_annotation}] pState\n\t\t# pState = warnIfStrictAnnot sp_annotation pState\n\t\t# (context, pState) = optionalContext (tokenBack pState)\n\t\t (attr_env, pState) = optionalCoercions pState\n\t\t= (makeSymbolType [] type context attr_env, pState)\n\twant_rest_of_symbol_type token [{sp_type=type=:{at_type = TA type_symb [] },sp_annotation} : types] pState\n\t\t# pState = warnIfStrictAnnot sp_annotation pState\n\t\t# (atypes,pState) = atypes_from_sptypes_and_warn_if_strict types pState\n\t \t# type = { type & at_type = TA { type_symb & type_arity = length atypes } atypes }\n\t\t (context, pState) = optionalContext (tokenBack pState)\n\t\t (attr_env, pState) = optionalCoercions pState\n\t\t= (makeSymbolType [] type context attr_env, pState)\n\twant_rest_of_symbol_type token [{sp_type=type=:{at_type = TV tv},sp_annotation} : types] pState\n\t\t# pState = warnIfStrictAnnot sp_annotation pState\n\t\t# (atypes,pState) = atypes_from_sptypes_and_warn_if_strict types pState\n\t \t# type = { type & at_type = CV tv :@: atypes }\n\t\t (context, pState) = optionalContext (tokenBack pState)\n\t\t (attr_env, pState) = optionalCoercions pState\n\t\t= (makeSymbolType [] type context attr_env, pState)\n\twant_rest_of_symbol_type token [{sp_type=type=:{at_type = TQualifiedIdent module_ident type_name [] },sp_annotation} : types] pState\n\t\t# pState = warnIfStrictAnnot sp_annotation pState\n\t\t# (atypes,pState) = atypes_from_sptypes_and_warn_if_strict types pState\n\t \t# type = { type & at_type = TQualifiedIdent module_ident type_name atypes }\n\t\t (context, pState) = optionalContext (tokenBack pState)\n\t\t (attr_env, pState) = optionalCoercions pState\n\t\t= (makeSymbolType [] type context attr_env, pState)\n\twant_rest_of_symbol_type token types pState\n\t\t= (makeSymbolType [] (MakeAttributedType TE) [] [], parseError \"symbol type\" (Yes token) \"->\" pState)\n\n\/*\n\tTypes\n*\/\n\nnameToTypeVar name pState\n\t# last_char_index = size name - 1\n\t| name.[last_char_index] == '^'\n\t\t# new_name = name % (0, last_char_index - 1)\n\t\t# (ident, pState) = stringToIdent new_name IC_Type pState\n\t\t= (GTV (MakeTypeVar ident), pState)\n\t\t# (ident, pState) = stringToIdent name IC_Type pState\n\t\t= (TV (MakeTypeVar ident), pState)\n\ninstance want TypeVar\nwhere\n\twant pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t= case token of\n\t\t\tIdentToken name\n\t\t\t\t| isLowerCaseName name\n\t\t\t\t\t# (ident, pState) = stringToIdent name IC_Type pState\n\t\t\t\t\t-> (MakeTypeVar ident, pState)\n\t\t\t\t\t-> (MakeTypeVar erroneousIdent, parseError \"Type variable\" (Yes token) \"\" pState)\n\t\t\t_\n\t\t\t\t-> (MakeTypeVar erroneousIdent, parseError \"Type variable\" (Yes token) \"\" pState)\n\n\/\/ Sjaak 210801 ...\n\nadjustAttribute :: !TypeAttribute Type *ParseState -> (!TypeAttribute, !*ParseState)\nadjustAttribute attr (TV {tv_ident}) pState\n\t= adjustAttributeOfTypeVariable attr tv_ident pState\nadjustAttribute attr (GTV {tv_ident}) pState\n\t= adjustAttributeOfTypeVariable attr tv_ident pState\nadjustAttribute attr type pState\n\t= (attr, pState)\n\nadjustAttributeOfTypeVariable :: !TypeAttribute !Ident !*ParseState -> (!TypeAttribute, !*ParseState)\nadjustAttributeOfTypeVariable TA_Anonymous {id_name} pState\n\t# (ident, pState) = stringToIdent id_name IC_TypeAttr pState\n\t= (TA_Var (makeAttributeVar ident), pState)\nadjustAttributeOfTypeVariable attr _ pState\n\t= (attr, pState)\n\n\/\/ ... Sjaak 210801\n\nstringToType :: !String !ParseState -> (!Type, !ParseState)\nstringToType name pState\n\t| isLowerCaseName name\n\t\t= nameToTypeVar name pState\n\t\t# (id, pState) = stringToIdent name IC_Type pState\n\t\t= (TA (MakeNewTypeSymbIdent id 0) [], pState)\n\/*\t| isUpperCaseName name\n\t\t= (TA (MakeNewTypeSymbIdent id 0) [], pState)\n\t\t= nameToTypeVar name pState\n*\/\n\/*\nstringToAType :: !String !Annotation !TypeAttribute !ParseState -> (!AType, !ParseState)\nstringToAType name annot attr pState\n\t# (id, pState) = stringToIdent name IC_Type pState\n\t| isUpperCaseName name\n\t\t= ({ at_annotation = annot, at_attribute = attr, at_type = TA (MakeNewTypeSymbIdent id 0) []}, pState)\n\t\t# (type_var, pState) = nameToTypeVar name pState\n\t\t= build_attributed_type_var attr annot type_var name pState\nwhere\n\tbuild_attributed_type_var TA_Anonymous annot type_var type_var_name pState\n\t\t# (attr_id, pState) = stringToIdent type_var_name IC_TypeAttr pState\n\t\t= ({ at_annotation = annot, at_attribute = TA_Var (makeAttributeVar attr_id), at_type = type_var }, pState)\n\tbuild_attributed_type_var attr annot type_var _ pState\n\t\t= ({ at_annotation = annot, at_attribute = attr, at_type = type_var }, pState)\n*\/\n\ninstance want SAType\nwhere\n\twant pState\n\t\t# (annotation,a_type,pState) = wantAnnotatedAType pState\n\t\t= ({s_annotation=annotation,s_type=a_type},pState)\n\n:: AnnotationWithPosition = NoAnnot | StrictAnnotWithPosition !FilePosition;\n\nwantAnnotatedATypeWithPositionT :: !Token !ParseState -> (!AnnotationWithPosition,!AType,!ParseState)\nwantAnnotatedATypeWithPositionT ForAllToken pState\n\t# (vars, pState)\t\t= wantUniversalQuantifiedVariables pState\n\t# (_,annotation,pState) = optionalAnnotWithPosition pState\n\t# (succ, atype, pState)\t= tryAnnotatedAType TA_None pState\n\t# atype = {atype & at_type = TFA vars atype.at_type}\n\t| succ\n\t\t= (annotation, atype, pState)\n\t\t= (annotation, atype, attributed_and_annotated_type_error pState)\nwantAnnotatedATypeWithPositionT noForAllToken pState\n\t= wantAnnotatedATypeWithPosition_noUniversalQuantifiedVariables (tokenBack pState)\n\nwantAnnotatedATypeWithPosition_noUniversalQuantifiedVariables pState\n\t# (_,annotation,pState) = optionalAnnotWithPosition pState\n\t# (succ, atype, pState)\t= tryAnnotatedAType TA_None pState\n\t| succ\n\t\t= (annotation, atype, pState)\n\t\t= (annotation, atype, attributed_and_annotated_type_error pState)\n\nwantAnnotatedAType :: !ParseState -> (!Annotation,!AType,!ParseState)\nwantAnnotatedAType pState\n\t# (vars , pState)\t\t= optionalUniversalQuantifiedVariables pState\t\n\t# (_,annotation,pState) = optionalAnnot pState\n\t| isEmpty vars\n\t\t# (succ, atype, pState)\t= tryAnnotatedAType TA_None pState\n\t\t| succ\n\t\t\t= (annotation, atype, pState)\n\t\t\t= (annotation, atype, attributed_and_annotated_type_error pState)\n\t\t# (succ, atype, pState)\t= tryAnnotatedAType TA_None pState\n\t\t# atype = {atype & at_type = TFA vars atype.at_type}\n\t\t| succ\n\t\t\t= (annotation, atype, pState)\n\t\t\t= (annotation, atype, attributed_and_annotated_type_error pState)\n\ntryAnnotatedAType :: !TypeAttribute !ParseState -> (!Bool, !AType,!ParseState)\ntryAnnotatedAType attr pState\n\t# (types, pState)\t\t= parseList tryBrackAType pState\n\t| isEmpty types\n\t\t= (False, {at_attribute = attr, at_type = TE}, pState)\n\t# (token, pState)\t\t= nextToken TypeContext pState\n\t| token == ArrowToken\n\t\t# (rtype, pState)\t= wantAType pState\n\t\t atype = make_curry_type attr types rtype\n\t\t= ( True, atype, pState)\n\t\/\/ otherwise (note that types is non-empty)\n\t# (atype, pState) = convertAAType types attr (tokenBack pState)\n\t= (True, atype, pState)\nwhere\n\tmake_curry_type attr [t1] res_type\n\t\t= {at_attribute = attr, at_type = t1 --> res_type}\n\tmake_curry_type attr [t1:tr] res_type\n\t\t= {at_attribute = attr, at_type = t1 --> make_curry_type TA_None tr res_type}\n\tmake_curry_type _ _ _ = abort \"make_curry_type: wrong assumption\"\n\n:: ParseResult :== Int\nParseOk:==0\nParseFailWithError:==1\nParseFailWithoutError:==2\n\ntryBrackAType_allow_universal_quantifier :: !TypeAttribute !ParseState -> (!Bool, AType, !ParseState)\ntryBrackAType_allow_universal_quantifier attr pState\n\t# (token, pState) = nextToken TypeContext pState\n\t# (result,atype,pState) = tryBrackATypeT_allow_universal_quantifier token attr pState\n\t= (result==ParseOk,atype,pState)\n\ntryBrackATypeT_allow_universal_quantifier :: !Token !TypeAttribute !ParseState -> (!ParseResult, AType, !ParseState)\ntryBrackATypeT_allow_universal_quantifier OpenToken attr pState\n\t\/\/ type of function or constructor argument\n\t# (token, pState) = nextToken TypeContext pState\n\t= case token of\n\t\tForAllToken\n\t\t\t# (vars,pState) = wantUniversalQuantifiedVariables pState \n\t\t\t (annot_with_pos, atype, pState) = wantAnnotatedATypeWithPosition_noUniversalQuantifiedVariables pState\n\t\t\t (token, pState) = nextToken TypeContext pState\n\t\t\t-> case token of\n\t\t\t\tBarToken\n\t\t\t\t\t# (contexts, pState) = want_contexts pState\n\t\t\t\t\t (token, pState) = nextToken TypeContext pState\n\t\t\t\t\t (succ,atype,pState)\n\t\t\t\t\t\t= case token of\n\t\t\t\t\t\t\tCloseToken\n\t\t\t\t\t\t\t\t# type = atype.at_type\n\t\t\t\t\t\t\t\t (attr, pState) = determAttr attr atype.at_attribute type pState\n\t\t\t\t\t\t\t\t pState = warnIfStrictAnnot annot_with_pos pState\n\t\t\t\t\t\t\t\t-> (ParseOk, {at_attribute = attr, at_type = type}, pState)\n\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t-> (ParseFailWithError, atype, parseError \"Simple type\" (Yes token) \"')' or ','\" pState)\n\t\t\t\t\t atype = {atype & at_type = TFAC vars atype.at_type contexts}\n\t\t\t\t\t-> (succ, atype, pState)\n\t\t\t\t_\n\t\t\t\t\t# atype = {atype & at_type = TFA vars atype.at_type}\n\t\t\t\t\t-> trySimpleTypeT_after_OpenToken_and_type token annot_with_pos atype attr pState\n\t\t_\n\t\t\t-> trySimpleTypeT_after_OpenToken token attr pState\ntryBrackATypeT_allow_universal_quantifier token attr pState\n\t= trySimpleTypeT token attr pState\n\ntryBrackSATypeWithPosition :: !ParseState -> (!Bool, SATypeWithPosition, !ParseState)\ntryBrackSATypeWithPosition pState\n\t\/\/ type of function argument\n\t# (succ, annot, attr, pState) = optionalAnnotAndAttrWithPosition pState\n\t| succ\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t# (result, atype, pState) = tryBrackATypeT_allow_universal_quantifier token attr pState\n\t\t# sa_type_wp = {sp_annotation=annot,sp_type=atype}\n\t\t| result==ParseOk\n\t\t\t= (True, sa_type_wp, pState)\n\t\t| result==ParseFailWithError\n\t\t\t= (False, sa_type_wp, pState)\n\t\t\t= (False, sa_type_wp, parseError \"symbol type\" (Yes token) \"type\" pState)\n\t\t# (succ, atype, pState) = tryBrackAType_allow_universal_quantifier attr pState\n\t\t= (succ, {sp_annotation=annot,sp_type=atype}, pState)\n\ntryBrackSAType :: !ParseState -> (!Bool, SAType, !ParseState)\ntryBrackSAType pState\n\t\/\/ type of constructor argument\n\t# (succ, annot, attr, pState) = optionalAnnotAndAttr pState\n\t| succ\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t# (result, atype, pState) = tryBrackATypeT_allow_universal_quantifier token attr pState\n\t\t# sa_type = {s_annotation=annot,s_type=atype}\n\t\t| result==ParseOk\n\t\t\t= (True, sa_type, pState)\n\t\t| result==ParseFailWithError\n\t\t\t= (False, sa_type, pState)\n\t\t\t= (False, sa_type, parseError \"constructor type\" (Yes token) \"type\" pState)\n\t\t# (succ, atype, pState) = tryBrackAType_allow_universal_quantifier attr pState\n\t\t= (succ, {s_annotation=annot,s_type=atype}, pState)\n\ninstance want AType\nwhere\n\twant pState = wantAType pState\n\ninstance want Type\nwhere\n\twant pState = wantType pState\n\nwantType :: !ParseState -> (!Type,!ParseState)\nwantType pState\n\t# (vars, pState)\t= optionalUniversalQuantifiedVariables pState\n\t| isEmpty vars\n\t\t# (succ, atype, pState)\t= tryAType False TA_None pState\n\t\t (succ2, type, pState)\t= tryATypeToType atype pState\n\t\t| succ&&succ2\n\t\t\t= (type, pState)\n\t\t\/\/ otherwise \/\/~ succ\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= (type, parseError \"type\" (Yes token) \"type\" pState)\n\t\/\/ ~(isEmpty vars)\n\t\t# (type, pState) = wantType pState\n\t\t= (TFA vars type, pState)\n\nwantAType :: !ParseState -> (!AType,!ParseState)\nwantAType pState\n\t# (succ, atype, pState)\t= tryAType True TA_None pState\n\t| succ\n\t\t= (atype, pState)\n\t\t= (atype, attributed_and_annotated_type_error pState)\n\nattributed_and_annotated_type_error pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= parseError \"atype\" (Yes token) \"attributed and annotated type\" pState\n\ntryType :: !ParseState -> (!Bool,!Type,!ParseState)\ntryType pState\n\t# (succ, atype, pState)\t= tryAType False TA_None pState\n\t (succ2, type, pState)\t= tryATypeToType atype pState\n\t= (succ&&succ2, type, pState)\n\ntryAType :: !Bool !TypeAttribute !ParseState -> (!Bool,!AType,!ParseState)\ntryAType tryAA attr pState\n\t# (vars , pState)\t\t= optionalUniversalQuantifiedVariables pState\n\t# (types, pState)\t\t= parseList tryBrackAType pState\n\t| isEmpty types\n\t\t| isEmpty vars\n\t\t\t= (False, {at_attribute = attr, at_type = TE}, pState)\n\t\t\/\/ otherwise \/\/ PK\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= (False, {at_attribute = attr, at_type = TFA vars TE}\n\t\t\t , parseError \"annotated type\" (Yes token) \"type\" (tokenBack pState))\n\t# (token, pState)\t\t= nextToken TypeContext pState\n\t| token == ArrowToken\n\t\t# (rtype, pState)\t= wantAType pState\n\t\t atype = make_curry_type attr types rtype\n\t\t| isEmpty vars\n\t\t\t= ( True, atype, pState)\n\t\t\t= ( True, { atype & at_type = TFA vars atype.at_type }, pState)\n\t\/\/ otherwise (not that types is non-empty)\n\/\/ Sjaak\t\n\t# (atype, pState) = convertAAType types attr (tokenBack pState)\n\t| isEmpty vars\n\t\t= (True, atype, pState)\n\t\t= (True, { atype & at_type = TFA vars atype.at_type }, pState)\n\/* PK\ntryFunctionType :: ![AType] !Annotation !TypeAttribute !ParseState -> (!Bool,!AType,!ParseState)\ntryFunctionType types annot attr pState\n\t# (rtype, pState)\t\t= wantAType pState\n\t= ( True\n\t , make_curry_type annot attr types rtype\n\t , pState\n\t )\n*\/\nwhere\n\tmake_curry_type attr [t1] res_type\n\t\t= {at_attribute = attr, at_type = t1 --> res_type}\n\tmake_curry_type attr [t1:tr] res_type\n\t\t= {at_attribute = attr, at_type = t1 --> make_curry_type TA_None tr res_type}\n\tmake_curry_type _ _ _ = abort \"make_curry_type: wrong assumption\"\n\n\/\/ Sjaak ...\nconvertAAType :: ![AType] !TypeAttribute !ParseState -> (!AType,!ParseState)\nconvertAAType [atype] attr pState\n\t# type\t\t\t\t= atype.at_type\n\t# (attr, pState)\t= determAttr attr atype.at_attribute type pState\n\t= ( {at_attribute = attr, at_type = type}, pState)\nconvertAAType [atype:atypes] attr pState\n\t# type\t\t\t\t= atype.at_type\n\t# (attr, pState)\t= determAttr_ attr atype.at_attribute type pState\n\t\twith\n\t\t\tdetermAttr_ :: !TypeAttribute !TypeAttribute !Type !ParseState -> (!TypeAttribute, !ParseState)\n\t\t\tdetermAttr_ TA_None (TA_Var {av_ident}) (TV {tv_ident}) pState\n\t\t\t\t| av_ident.id_name==tv_ident.id_name\n\t\t\t\t\t= (TA_Anonymous,pState)\n\t\t\tdetermAttr_ attr1 attr2 type pState\n\t\t\t\t= determAttr attr1 attr2 type pState\n\t# (type, pState)\t= convert_list_of_types atype.at_type atypes pState\n\t= ({at_attribute = attr, at_type = type}, pState)\nwhere\n\tconvert_list_of_types (TA sym []) types pState\n\t\t= (TA { sym & type_arity = length types } types, pState)\n\tconvert_list_of_types (TV tv) types pState\n\t\t= (CV tv :@: types, pState)\n\tconvert_list_of_types TArrow [type1, type2]\tpState\n\t\t= (type1 --> type2, pState)\n\tconvert_list_of_types TArrow [type1] pState\n\t\t= (TArrow1 type1, pState)\n\tconvert_list_of_types (TArrow1 type1) [type2] pState\n\t\t= (type1 --> type2, pState)\n\tconvert_list_of_types (TQualifiedIdent module_ident type_name []) types pState\n\t\t= (TQualifiedIdent module_ident type_name types, pState)\n\tconvert_list_of_types _ types pState\n\t\t= (TE, parseError \"Type\" No \"ordinary type variable\" pState)\n\/\/ ... Sjaak\n\/*\ntryApplicationType _ annot attr pState\n\t= (False, {at_annotation = annot, at_attribute = attr, at_type = TE}, pState)\n*\/\ntryBrackType :: !ParseState -> (!Bool, Type, !ParseState)\ntryBrackType pState\n\t# (succ, atype, pState) \t= trySimpleType TA_None pState\n\t (succ2, type, pState)\t\t= tryATypeToType atype pState\n\t= (succ&&succ2, type, pState)\n\ntryBrackAType :: !ParseState -> (!Bool, AType, !ParseState)\ntryBrackAType pState\n\t# (_, attr, pState)\t= warnAnnotAndOptionalAttr pState\n\t= trySimpleType attr pState\n\ntrySimpleType :: !TypeAttribute !ParseState -> (!Bool, !AType, !ParseState)\ntrySimpleType attr pState\n\t# (token, pState)\t\t= nextToken TypeContext pState\n\t# (result,atype,pState) = trySimpleTypeT token attr pState\n\t= (result==ParseOk,atype,pState)\n\nis_tail_strict_list_or_nil pState\n\t# (square_close_position, pState) = getPosition pState\n\t# pState=tokenBack pState\n\t# (exclamation_position, pState) = getPosition pState\n\t# pState=tokenBack pState\n\t# (square_open_position, pState) = getPosition pState\n\t# (exclamation_token,pState) = nextToken TypeContext pState\n\t# (square_close_token,pState) = nextToken TypeContext pState\n\t| exclamation_position.fp_col+1==square_close_position.fp_col && exclamation_position.fp_line==square_close_position.fp_line\n\t\t&& (square_open_position.fp_col+1<>exclamation_position.fp_col || square_open_position.fp_line<>exclamation_position.fp_line)\n\t\t= (True,pState)\n\t\t= (False,pState)\n\ntrySimpleTypeT :: !Token !TypeAttribute !ParseState -> (!ParseResult, !AType, !ParseState)\ntrySimpleTypeT (IdentToken id) attr pState\n\t| isLowerCaseName id\n\t\t# (typevar, pState)\t= nameToTypeVar id pState\n\t\t (attr, pState)\t= adjustAttribute attr typevar pState\n\t\t= (ParseOk, {at_attribute = attr, at_type = typevar}, pState)\n\t| otherwise \/\/ | isUpperCaseName id || isFunnyIdName id\n\t# (type, pState) = stringToType id pState\n\t= (ParseOk, {at_attribute = attr, at_type = type}, pState)\ntrySimpleTypeT SquareOpenToken attr pState\n\t# (token, pState) = nextToken TypeContext pState\n\t# (head_strictness,token,pState) = wantHeadStrictness token pState\n\t\twith\n\t\t\twantHeadStrictness :: Token *ParseState -> *(!Int,!Token,!*ParseState)\n\t\t\twantHeadStrictness ExclamationToken pState\n\t\t\t\t# (token,pState) = nextToken TypeContext pState\n\t\t\t\t= (HeadStrict,token,pState)\n\t\t\twantHeadStrictness HashToken pState\n\t\t\t\t# (token,pState) = nextToken TypeContext pState\n\t\t\t\t= (HeadUnboxed,token,pState)\n\t\t\twantHeadStrictness token pState\n\t\t\t\t= (HeadLazy,token,pState)\n\t| token == SquareCloseToken\n\t\t| head_strictness==HeadStrict\n\t\t\t# (tail_strict,pState) = is_tail_strict_list_or_nil pState\n\t\t\t| tail_strict\n\t\t\t\t# list_symbol = makeTailStrictListTypeSymbol HeadLazy 0\n\t\t \t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol []}, pState)\t\t\t\t\t\n\t\t\t\t# list_symbol = makeListTypeSymbol head_strictness 0\n\t\t \t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol []}, pState)\n\t\t# list_symbol = makeListTypeSymbol head_strictness 0\n \t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol []}, pState)\n\n\t| token==ExclamationToken\n\t\t# (token,pState) = nextToken TypeContext pState\n\t\t| token==SquareCloseToken\n\t\t\t# list_symbol = makeTailStrictListTypeSymbol head_strictness 0\n \t\t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol []}, pState)\n\t\t\t= (ParseFailWithError, {at_attribute = attr, at_type = TE}, parseError \"List type\" (Yes token) \"]\" pState)\n\n\t# (type, pState)\t= wantAType (tokenBack pState)\n\t (token, pState)\t= nextToken TypeContext pState\n\t| token == SquareCloseToken\n\t\t# list_symbol = makeListTypeSymbol head_strictness 1\n\t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol [type]}, pState)\n\n\t| token==ExclamationToken\n\t\t# (token,pState) = nextToken TypeContext pState\n\t\t| token==SquareCloseToken\n\t\t\t# list_symbol = makeTailStrictListTypeSymbol head_strictness 1\n\t\t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol [type]}, pState)\n\t\t\t= (ParseFailWithError, {at_attribute = attr, at_type = TE}, parseError \"List type\" (Yes token) \"]\" pState)\n\n\t\/\/ otherwise \/\/ token <> SquareCloseToken\n\t\t= (ParseFailWithError, {at_attribute = attr, at_type = TE}, parseError \"List type\" (Yes token) \"]\" pState)\ntrySimpleTypeT OpenToken attr pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= trySimpleTypeT_after_OpenToken token attr pState\ntrySimpleTypeT CurlyOpenToken attr pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == CurlyCloseToken\n\t\t# array_symbol = makeLazyArraySymbol 0\n\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol []}, pState)\n\t| token == HashToken\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == CurlyCloseToken\n\t\t\t# array_symbol = makeUnboxedArraySymbol 0\n\t\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol []}, pState)\n\t\t\/\/ otherwise \/\/ token <> CurlyCloseToken\n\t \t\t# (atype, pState)\t\t\t= wantAType (tokenBack pState)\n \t\t\t pState\t\t\t\t\t= wantToken TypeContext \"unboxed array type\" CurlyCloseToken pState\n \t\t\t array_symbol = makeUnboxedArraySymbol 1\n \t\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol [atype]}, pState)\n\t| token == ExclamationToken\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == CurlyCloseToken\n\t\t\t# array_symbol = makeStrictArraySymbol 0\n\t\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol []}, pState)\n\t\t\/\/ otherwise \/\/ token <> CurlyCloseToken\n\t \t\t# (atype,pState)\t\t\t= wantAType (tokenBack pState)\n \t\t\t pState\t\t\t\t\t= wantToken TypeContext \"strict array type\" CurlyCloseToken pState\n \t\t\t array_symbol = makeStrictArraySymbol 1\n \t\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol [atype]}, pState)\n \t\/\/ otherwise\n \t\t# (atype,pState)\t\t\t= wantAType (tokenBack pState)\n \t\t pState\t\t\t\t\t= wantToken TypeContext \"lazy array type\" CurlyCloseToken pState\n\t\t array_symbol = makeLazyArraySymbol 1\n\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol [atype]}, pState)\ntrySimpleTypeT StringTypeToken attr pState\n\t# type = makeStringType\n\t= (ParseOk, {at_attribute = attr, at_type = type}, pState)\ntrySimpleTypeT (QualifiedIdentToken module_name ident_name) attr pState\n\t| not (isLowerCaseName ident_name)\n\t\t# (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Type pState\n\t\t# type = TQualifiedIdent module_id ident_name []\n\t\t= (ParseOk, {at_attribute = attr, at_type = type}, pState)\ntrySimpleTypeT token attr pState\n\t# (bt, pState) = try token pState\n\t= case bt of\n\t\tYes bt\t-> (ParseOk , {at_attribute = attr, at_type = TB bt}, pState)\n\t\tno\t\t-> (ParseFailWithoutError, {at_attribute = attr, at_type = TE} , pState)\n\ntrySimpleTypeT_after_OpenToken :: !Token !TypeAttribute !ParseState -> (!ParseResult, !AType, !ParseState)\ntrySimpleTypeT_after_OpenToken CommaToken attr pState\n\t# (tup_arity, pState)\t\t= determine_arity_of_tuple 2 pState\n\t tuple_symbol = makeTupleTypeSymbol tup_arity 0\n\t= (ParseOk, {at_attribute = attr, at_type = TA tuple_symbol []}, pState)\t\n where\n\tdetermine_arity_of_tuple :: !Int !ParseState -> (!Int, !ParseState)\n\tdetermine_arity_of_tuple arity pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| CommaToken == token\n \t\t\t= determine_arity_of_tuple (inc arity) pState\n\t\t| CloseToken == token\n\t\t\t= (arity, pState)\n\t\t\t= (arity, parseError \"tuple type\" (Yes token) \")\" pState)\ntrySimpleTypeT_after_OpenToken ArrowToken attr pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == CloseToken\n\t\t= (ParseOk, {at_attribute = attr, at_type = TArrow}, pState)\n\t\t= (ParseFailWithError,{at_attribute = attr, at_type = TE},\n\t\t\tparseError \"arrow type\" (Yes token) \")\" pState)\ntrySimpleTypeT_after_OpenToken CloseToken attr pState\n\t#! unit_type_ident = predefined_idents.[PD_UnitType]\n\t= (ParseOk,{at_attribute=attr,at_type=TA (MakeNewTypeSymbIdent unit_type_ident 0) []},pState)\ntrySimpleTypeT_after_OpenToken token attr pState\n\t# (annot_with_pos,atype, pState) = wantAnnotatedATypeWithPositionT token pState\n\t (token, pState)\t= nextToken TypeContext pState\n\t= trySimpleTypeT_after_OpenToken_and_type token annot_with_pos atype attr pState\n\ntrySimpleTypeT_after_OpenToken_and_type CloseToken annot_with_pos atype attr pState\n\t# type\t\t\t\t= atype.at_type\n\t (attr, pState)\t= determAttr attr atype.at_attribute type pState\n\t pState = warnIfStrictAnnot annot_with_pos pState\n\t= (ParseOk, {at_attribute = attr, at_type = type}, pState)\ntrySimpleTypeT_after_OpenToken_and_type CommaToken annot_with_pos atype attr pState\n\t\/\/ TupleType\n\t# (satypes, pState)\t= wantSequence CommaToken TypeContext pState\n\t pState\t\t\t= wantToken TypeContext \"tuple type\" CloseToken pState\n\t satypes\t\t\t= [{s_annotation=(case annot_with_pos of NoAnnot -> AN_None; StrictAnnotWithPosition _ -> AN_Strict),s_type=atype}:satypes]\n\t arity\t\t\t\t= length satypes\n \t tuple_symbol = makeTupleTypeSymbol arity arity\n\t= (ParseOk, {at_attribute = attr, at_type = TAS tuple_symbol (atypes_from_satypes satypes) (strictness_from_satypes satypes)}, pState)\ntrySimpleTypeT_after_OpenToken_and_type token annot_with_pos atype attr pState\n\t= (ParseFailWithError, atype, parseError \"Simple type\" (Yes token) \"')' or ','\" pState)\n\ninstance try BasicType\nwhere\n\ttry IntTypeToken\t pState = (Yes BT_Int\t\t\t, pState)\n\ttry CharTypeToken\t pState\t= (Yes BT_Char\t\t\t, pState)\n\ttry BoolTypeToken\t pState\t= (Yes BT_Bool\t\t\t, pState)\n\ttry RealTypeToken\t pState\t= (Yes BT_Real\t\t\t, pState)\n\ttry DynamicTypeToken pState\t= (Yes BT_Dynamic\t\t, {pState & ps_flags=pState.ps_flags bitor PS_DynamicTypeUsedMask})\n\ttry FileTypeToken\t pState = (Yes BT_File\t\t\t, pState)\n\ttry WorldTypeToken\t pState = (Yes BT_World\t\t\t, pState)\n\ttry _\t\t\t\t pState = (No\t\t\t\t\t, tokenBack pState)\n\ndetermAnnot :: !Annotation !Annotation !ParseState -> (!Annotation, !ParseState)\ndetermAnnot AN_None annot2 pState = (annot2, pState)\ndetermAnnot annot1 AN_None pState = (annot1, pState)\ndetermAnnot annot1 annot2 pState\n\t= (annot1, parseError \"simple type\" No (\"More type annotations, \"+toString annot1+\" and \"+toString annot2+\", than\") pState)\n\ndetermAttr :: !TypeAttribute !TypeAttribute !Type !ParseState -> (!TypeAttribute, !ParseState)\ndetermAttr TA_None attr2 type pState = adjustAttribute attr2 type pState\ndetermAttr attr1 TA_None type pState = adjustAttribute attr1 type pState\ndetermAttr attr1 attr2 type pState\n\t= (attr1, parseError \"simple type\" No (\"More type attributes, \"+toString attr1+\" and \"+toString attr2+\", than\") pState)\n\nwantDynamicTypeInExpression :: !*ParseState -> *(!DynamicType,!*ParseState)\nwantDynamicTypeInExpression pState \n\t# (atype, pState) = want pState\n\t= case atype.at_type of\n\t\tTFA vars type\n\t\t\t# atype = {atype & at_type=type}\n\t\t\t (contexts, pState) = optionalContext pState\n\t\t\t-> ({dt_uni_vars=vars, dt_type=atype, dt_global_vars=[], dt_contexts=contexts}, pState)\n\t\t_\n\t\t\t-> ({dt_uni_vars=[], dt_type=atype, dt_global_vars=[], dt_contexts=[]}, pState)\n\nwantDynamicTypeInPattern :: !*ParseState -> *(!DynamicType,!*ParseState)\nwantDynamicTypeInPattern pState \n\t# (atype, pState) = want pState\n\t= case atype.at_type of\n\t\tTFA vars type\n\t\t\t# atype = {atype & at_type=type}\n\t\t\t (contexts, pState) = optionalContext pState\n\t\t\t-> ({dt_uni_vars=vars, dt_type=atype, dt_global_vars=[], dt_contexts=contexts}, pState)\n\t\t_\n\t\t\t # (contexts, pState) = optionalContext pState\n\t\t\t-> ({dt_uni_vars=[], dt_type=atype, dt_global_vars=[], dt_contexts=contexts}, pState)\n\noptionalExistentialQuantifiedVariables :: !*ParseState -> *(![ATypeVar],!*ParseState)\noptionalExistentialQuantifiedVariables pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= case token of\n\t\tExistsToken\n\t\t\t# (vars, pState) = wantList \"existential quantified variable(s)\" tryQuantifiedTypeVar pState\n\t\t\t-> (vars, wantToken TypeContext \"Existential Quantified Variables\" ColonToken pState)\n\t\t_\t-> ([], tokenBack pState)\n\n\/* Sjaak 041001\nwhere\n\ttry_existential_type_var :: !ParseState -> (Bool,ATypeVar,ParseState)\n\ttry_existential_type_var pState\n\t\t# (token, pState)\t= nextToken TypeContext pState\n\t\t= case token of\n\t\t\tDotToken\n\t\t\t\t# (typevar, pState)\t= wantTypeVar pState\n\t\t\t\t-> (True, {atv_attribute = TA_Anonymous, atv_annotation = AN_None, atv_variable = typevar}, pState)\n\t\t\t_\n\t\t\t\t# (succ, typevar, pState)\t= tryTypeVarT token pState\n\t\t\t\t| succ\n\t\t\t\t\t#\tatypevar = {atv_attribute = TA_None, atv_annotation = AN_None, atv_variable = typevar}\n\t\t\t\t\t->\t(True,atypevar,pState)\n\t\t\t\t\t->\t(False,abort \"no ATypeVar\",pState)\n*\/\n\noptionalUniversalQuantifiedVariables :: !*ParseState -> *(![ATypeVar],!*ParseState)\noptionalUniversalQuantifiedVariables pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= case token of\n\t\tForAllToken\n\t\t\t-> wantUniversalQuantifiedVariables pState \n\t\t_\t-> ([], tokenBack pState)\n\nwantUniversalQuantifiedVariables :: !*ParseState -> *(![ATypeVar],!*ParseState)\nwantUniversalQuantifiedVariables pState\n\t# (vars, pState) = wantList \"universal quantified variable(s)\" tryQuantifiedTypeVar pState\n\t= (vars, wantToken TypeContext \"Universal Quantified Variables\" ColonToken pState)\n\ntryQuantifiedTypeVar :: !ParseState -> (Bool, ATypeVar, ParseState)\ntryQuantifiedTypeVar pState\n\t# (token, pState)\t\t\t= nextToken TypeContext pState\n \t (succ, attr, pState)\t\t= try_attribute token pState\n \t| succ\n\t\t# (typevar, pState)\t= wantTypeVar pState\n\t\t (attr, pState)\t= adjustAttributeOfTypeVariable attr typevar.tv_ident pState\n\t\t= (True, {atv_attribute = attr, atv_variable = typevar}, pState)\n\t# (succ, typevar, pState) = tryTypeVarT token pState\n\t| succ\n\t\t= (True, {atv_attribute = TA_None, atv_variable = typevar}, pState)\n\t\t= (False, abort \"no ATypeVar\", pState)\nwhere\t\t\t\n\ttry_attribute DotToken pState = (True,\tTA_Anonymous,\tpState)\n\ttry_attribute AsteriskToken\tpState = (True,\tTA_Unique,\t\tpState)\n\ttry_attribute token \tpState = (False,\tTA_None,\tpState)\n\ntryATypeToType :: !AType !ParseState -> (!Bool, !Type, !ParseState)\ntryATypeToType atype pState\n\/*\t| atype.at_annotation <> AN_None\n\t\t= ( False\n\t\t , atype.at_type\n\t\t , parseError \"simple type\" No (\"type instead of type annotation \"+toString atype.at_annotation) pState\n\t\t )\n*\/\t| atype.at_attribute <> TA_None\n\t\t= ( False\n\t\t , atype.at_type\n\t\t , parseError \"simple type\" No (\"type instead of type attribute \"+toString atype.at_attribute) pState\n\t\t )\n\t\/\/ otherwise\n\t\t= (True, atype.at_type, pState)\n\n\/*\n\tExpressions\n*\/\ncIsAPattern\t\t:== True\ncIsNotAPattern\t:== False\n\nwantExpressionOrPattern :: !Bool !ParseState -> (!ParsedExpr, !ParseState)\nwantExpressionOrPattern is_pattern pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCharListToken charList \/\/ To produce a better error message\n\t\t\t->\tcharListError charList pState\n\t\t_\t| is_pattern\n\t\t\t\t->\twantPatternT token pState\n\t\t\t\t->\twantExpressionT token pState\n\nwantPattern :: !ParseState -> (!ParsedExpr, !ParseState)\nwantPattern pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCharListToken charList \/\/ To produce a better error message\n\t\t\t->\tcharListError charList pState\n\t\t_\n\t\t\t->\twantPatternT token pState\n\nwantExpression :: !ParseState -> (!ParsedExpr, !ParseState)\nwantExpression pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCharListToken charList \/\/ To produce a better error message\n\t\t\t->\tcharListError charList pState\n\t\t_\n\t\t\t->\twantExpressionT token pState\n\nwantPatternWithoutDefinitions :: !ParseState -> (!ParsedExpr, !ParseState)\nwantPatternWithoutDefinitions pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCharListToken charList \/\/ To produce a better error message\n\t\t\t->\tcharListError charList pState\n\t\t_\n\t\t\t->\twantPatternWithoutDefinitionsT token pState\n\ncharListError charList pState\n\t= (PE_Empty, parseError \"Expression\" No (\"List brackets, [ and ], around charlist '\"+charList+\"'\") pState)\n\nwantExpressionT :: !Token !ParseState -> (!ParsedExpr, !ParseState)\n\/\/ FIXME, case, let and if expression should also be recognised here\n\/\/ and not in trySimpleNonLhsExpressionT, for example\n\/\/ Start = id if True id id id 17\n\/\/ is currently allowed\nwantExpressionT DynamicToken pState\n\t# (dyn_expr, pState) = wantExpression pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == DoubleColonToken\n\t\t# (dyn_type, pState) = wantDynamicTypeInPattern\/*wantDynamicTypeInExpression*\/ pState\n\t\t= (PE_Dynamic dyn_expr (Yes dyn_type), pState)\n\t\t= (PE_Dynamic dyn_expr No, tokenBack pState)\nwantExpressionT token pState\n\t# (succ, expr, pState) = tryExtendedSimpleExpressionT token pState\n\t| succ\n\t\t# (exprs, pState) = parseList tryExtendedSimpleExpression pState\n\t\t= (combineExpressions expr exprs, pState)\n\t\t= case token of\n\t\t\tCharListToken charList\n\t\t\t\t-> (PE_Empty, parseError \"RHS expression\" No (\"List brackets, [ and ], around charlist '\"+charList+\"'\") pState)\n\t\t\t_\t-> (PE_Empty, parseError \"RHS expression\" (Yes token) \"\" pState)\n\nwantPatternT :: !Token !ParseState -> (!ParsedExpr, !ParseState)\nwantPatternT token pState\n\t# (exp, pState)\t= wantPatternT2 token pState\n\t# (token, pState)\t= nextToken FunctionContext pState\n\t| token == DoubleColonToken\n\t\t# (dyn_type, pState) = wantDynamicTypeInPattern pState\n\t\t= (PE_DynamicPattern exp dyn_type, pState)\n\t\t= (exp, tokenBack pState)\nwhere\n\twantPatternT2 :: !Token !ParseState -> (!ParsedExpr, !ParseState)\n\twantPatternT2 (IdentToken name) pState \/* to make a=:C x equivalent to a=:(C x) *\/\n\t\t| isLowerCaseName name\n\t\t\t# (id, pState)\t\t= stringToIdent name IC_Expression pState\n\t\t\t (token, pState)\t= nextToken FunctionContext pState\n\t\t\t| token == DefinesColonToken \n\t\t\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t\t\t= case token of\n\t\t\t\t\tIdentToken name\n\t\t\t\t\t\t| ~ (isLowerCaseName name)\n\t\t\t\t\t\t\t#\t(constructor, pState) = stringToIdent name IC_Expression pState\n\t\t\t\t\t\t\t\t(args, pState)\t= parseList trySimplePattern pState\n\t\t\t\t\t\t\t->\t(PE_Bound { bind_dst = id, bind_src = combineExpressions (PE_Ident constructor) args }, pState)\n\t\t\t\t\t_\t# (succ, expr, pState) = trySimplePatternT token pState\n\t\t\t\t\t\t| succ\n\t\t\t\t\t\t\t# expr1 = PE_Bound { bind_dst = id, bind_src = expr }\n\t\t\t\t\t\t\t# (exprs, pState) = parseList trySimplePattern pState\n\t\t\t\t\t\t\t->\t(combineExpressions expr1 exprs, pState)\n\t\t\t\t\t\t\/\/ not succ\n\t\t\t\t\t\t\t-> (PE_Empty, parseError \"LHS expression\" (Yes token) \"\" pState)\n\t\t\t| token == DoubleColonToken\n\t\t\t\t# (dyn_type, pState) = wantDynamicTypeInPattern pState\n\t\t\t\t= (PE_DynamicPattern (PE_Ident id) dyn_type, pState)\n\t\t\t\/\/ token <> DefinesColonToken \/\/ token back and call to wantPatternT2 would do also.\n\t\t\t# (exprs, pState) = parseList trySimplePattern (tokenBack pState)\n\t\t\t= (combineExpressions (PE_Ident id) exprs, pState)\n\twantPatternT2 token pState\n\t\t# (succ, expr, pState) = trySimplePatternT token pState\n\t\t| succ\n\t\t\t# (exprs, pState) = parseList trySimplePattern pState\n\t\t\t= (combineExpressions expr exprs, pState)\n\t\t\t= (PE_Empty, parseError \"LHS expression\" (Yes token) \"\" pState)\n\nwantPatternWithoutDefinitionsT :: !Token !ParseState -> (!ParsedExpr, !ParseState)\nwantPatternWithoutDefinitionsT token pState\n\t# (succ, expr, pState) = trySimplePatternWithoutDefinitionsT token pState\n\t| succ\n\t\t# (exprs, pState) = parseList trySimplePatternWithoutDefinitions pState\n\t\t= (combineExpressions expr exprs, pState)\n\t\t= (PE_Empty, parseError \"pattern\" (Yes token) \"\" pState)\n\ncombineExpressions expr []\n\t= expr\ncombineExpressions expr exprs\n\t= make_app_exp expr exprs\nwhere\n\tmake_app_exp exp []\n\t\t= exp\n\tmake_app_exp exp exprs\n\t\t= PE_List [exp : exprs]\n\ntrySimplePattern :: !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntrySimplePattern pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= trySimplePatternT token pState\n\ntrySimplePatternWithoutDefinitions :: !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntrySimplePatternWithoutDefinitions pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= trySimplePatternWithoutDefinitionsT token pState\n\ntryExtendedSimpleExpression :: !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntryExtendedSimpleExpression pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= tryExtendedSimpleExpressionT token pState\n\ntryExtendedSimpleExpressionT :: !Token !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntryExtendedSimpleExpressionT token pState\n\t# (succ, expr, pState) = trySimpleExpressionT token pState\n\t| succ\n\t\t# (expr, pState) = extend_expr_with_selectors expr pState\n\t\t= (True, expr, pState)\n\t\t= (False, PE_Empty, pState)\nwhere\n\textend_expr_with_selectors :: !ParsedExpr !ParseState -> (!ParsedExpr, !ParseState)\n\textend_expr_with_selectors exp pState \n \t\t# (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tDotToken\n\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t (selectors, token, pState) = wantSelectors token pState\n\t\t\t\t exp = PE_Selection ParsedNormalSelector exp selectors\n\t\t\t\t-> case token of\n\t\t\t\t\tDefinesColonToken\n\t\t\t\t\t\t-> parse_matches_expression exp pState\n\t\t\t\t\t_\n\t\t\t\t\t\t-> (exp, tokenBack pState)\n\t\t\tExclamationToken\n\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\/\/ JVG added for strict lists:\n\t\t\t\t| token==SquareCloseToken\n\t\t\t\t\t-> (exp, tokenBack (tokenBack pState))\n\/\/\t\t\t\n\t\t\t\t# (selectors, token, pState) = wantSelectors token pState\n\t\t\t\t exp = PE_Selection (ParsedUniqueSelector False) exp selectors\n\t\t\t\t-> case token of\n\t\t\t\t\tDefinesColonToken\n\t\t\t\t\t\t-> parse_matches_expression exp pState\n\t\t\t\t\t_\n\t\t\t\t\t\t-> (exp, tokenBack pState)\n\t\t\tDefinesColonToken\n\t\t\t\t-> parse_matches_expression exp pState\n\t\t\t_\n\t\t\t\t-> (exp, tokenBack pState)\n\n\tparse_matches_expression exp pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tIdentToken name\n\t\t\t\t| not (isLowerCaseName name)\n\t\t\t\t\t# (id, pState) = stringToIdent name IC_Expression pState\n\t\t\t\t\t (pattern_args,pState) = parse_wild_cards pState\n\t\t\t\t\t pattern = if (isEmpty pattern_args) (PE_Ident id) (PE_List [PE_Ident id:pattern_args])\n\t\t\t\t\t-> matches_expression exp pattern pState\n\t\t\t\/\/ to do: qualified ident\n\t\t\t_\n\t\t\t\t# (succ, pattern, pState) = trySimplePatternWithoutDefinitionsT token pState\n\t\t\t\t| succ\n\t\t\t\t\t-> matches_expression exp pattern pState\n\t\t\t\t\t# pState = parseError \"pattern\" (Yes token) \"\" pState\n\t\t\t\t\t-> matches_expression exp PE_Empty pState\n\n\tparse_wild_cards pState\n\t \t# (token, pState) = nextToken FunctionContext pState\n\t \t= case token of\n\t \t\tWildCardToken\n\t\t\t\t# (pattern_args,pState) = parse_wild_cards pState\n\t \t\t\t-> ([PE_WildCard:pattern_args],pState)\n\t \t\t_\n\t \t\t\t-> ([],tokenBack pState);\n\n\tmatches_expression exp pattern pState\n\t\t# (case_ident, pState) = internalIdent \"_c\" pState\n\t\t (fname,linenr,pState) = getFileAndLineNr pState\n\t\t position = LinePos fname linenr\n\t\t= (PE_Matches case_ident exp pattern position, pState)\n\nwantSelectors :: Token *ParseState -> *(![ParsedSelection], !Token, !*ParseState)\nwantSelectors token pState\n\t# (selector, pState) = want_selector token pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == DotToken\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t (selectors, token, pState) = wantSelectors token pState\n\t\t= (selector ++ selectors, token, pState)\n\t\t= (selector, token, pState)\nwhere\n\twant_selector :: !Token !*ParseState -> *(![ParsedSelection], !*ParseState)\n\twant_selector SquareOpenToken pState\n\t\t# (array_selectors, pState) = want_array_selectors pState\n\t\t= (array_selectors, wantToken FunctionContext \"array selector\" SquareCloseToken pState)\n\t\twhere\n\t\t\twant_array_selectors :: !*ParseState -> *(![ParsedSelection], !*ParseState)\n\t\t\twant_array_selectors pState\n\t \t\t\t# (index_expr, pState) = wantExpression pState\n\t\t\t\t selector = PS_Array index_expr\n\t \t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t\t| token == CommaToken\n\t\t\t\t\t# (selectors, pState) = want_array_selectors pState\n\t\t\t\t\t= ([selector : selectors], pState)\n\t\t\t\t\t= ([selector], tokenBack pState)\n\twant_selector (IdentToken name) pState\n\t\t| isUpperCaseName name\n\t\t\t# pState = wantToken FunctionContext \"record selector\" DotToken pState\n\t\t\t (type_id, pState) = stringToIdent name IC_Type pState\n\t\t\t= want_field_after_record_type (RecordNameIdent type_id) pState\n\t\t\t# (selector_id, pState) = stringToIdent name IC_Selector pState\n\t\t\t= ([PS_Record selector_id NoRecordName], pState)\n\twant_selector (QualifiedIdentToken module_name ident_name) pState\n\t\t| isUpperCaseName ident_name\n\t \t\t# pState = wantToken FunctionContext \"record selector\" DotToken pState\n\t \t\t (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Type pState\n\t\t\t= want_field_after_record_type (RecordNameQualifiedIdent module_id ident_name) pState\n\t\t\t# (module_id, pState) = stringToIdent module_name (IC_Module NoQualifiedIdents) pState\n\t\t\t= ([PS_QualifiedRecord module_id ident_name NoRecordName], pState)\n\twant_selector token pState\n\t\t= ([PS_Erroneous], parseError \"simple RHS expression\" (Yes token) \"\" pState)\n\n\twant_field_after_record_type record_name pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t= case token of\n\t\t\tIdentToken field_name\n\t\t\t\t| isLowerCaseName field_name\n\t\t\t\t\t# (selector_id, pState) = stringToIdent field_name IC_Selector pState\n\t\t\t\t\t-> ([PS_Record selector_id record_name], pState)\n\t\t\tQualifiedIdentToken module_name field_name\n\t\t\t\t| isLowerCaseName field_name\n\t\t\t\t\t# (module_id, pState) = stringToIdent module_name (IC_Module NoQualifiedIdents) pState\n\t\t\t\t\t-> ([PS_QualifiedRecord module_id field_name record_name], pState)\n\t\t\t_\n\t\t\t\t-> ([PS_Erroneous], parseError \"record field\" (Yes token) \"lower case ident\" pState)\n\ntrySimplePatternT :: !Token !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntrySimplePatternT (IdentToken name) pState\n\t# (id, pState) = stringToIdent name IC_Expression pState\n\t| isLowerCaseName name\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == DefinesColonToken\n\t\t\t# (succ, expr, pState) = trySimplePattern pState\n\t\t\t| succ\n\t\t\t\t= (True, PE_Bound { bind_dst = id, bind_src = expr }, pState)\n\t\t\t\t= (True, PE_Empty, parseError \"simple expression\" No \"expression\" pState)\n\t\t\t= (True, PE_Ident id, tokenBack pState)\n\t\t= (True, PE_Ident id, pState)\ntrySimplePatternT SquareOpenToken pState\n\t# (list_expr, pState) = wantListExp cIsAPattern pState\n\t= (True, list_expr, pState)\ntrySimplePatternT OpenToken pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCloseToken\n\t\t\t#! unit_cons_ident = predefined_idents.[PD_UnitConsSymbol]\n\t\t\t-> (True,PE_Ident unit_cons_ident,pState)\n\t\t_\n\t\t\t# (args=:[exp:exps], pState) = want_pattern_list_t token pState\n\t\t\t pState = wantToken FunctionContext \"pattern list\" CloseToken pState\n\t\t\t| isEmpty exps\n\t\t\t\t-> case exp of\n\t\t\t\t\tPE_Ident id\n\t\t\t\t\t\t-> (True, PE_List [exp], pState)\n\t\t\t\t\t_\n\t\t\t\t\t\t-> (True, exp, pState)\n\t\t\t\t-> (True, PE_Tuple args, pState)\nwhere\n\twant_pattern_list_t token pState\n\t\t# (expr, pState)\n\t\t\t= case token of\n\t\t\t\tCharListToken charList \/\/ To produce a better error message\n\t\t\t\t\t->\tcharListError charList pState\n\t\t\t\t_\n\t\t\t\t\t->\twantPatternT token pState\n\t\t= want_pattern_list_rest expr pState\n\n\twant_pattern_list pState\n\t\t# (expr, pState) = wantPattern pState\n\t\t= want_pattern_list_rest expr pState\n\n\twant_pattern_list_rest expr pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (exprs, pState) = want_pattern_list pState\n\t\t\t= ([expr : exprs], pState)\n\t\t\t= ([expr], tokenBack pState)\ntrySimplePatternT CurlyOpenToken pState\n\t# (rec_or_aray_exp, pState) = wantRecordOrArrayExp cIsAPattern pState \n\t= (True, rec_or_aray_exp, pState)\ntrySimplePatternT (IntToken int_string) pState\n\t# (ok,int) = string_to_int int_string\n\t| ok\n\t\t= (True, PE_Basic (BVInt int), pState)\n\t\t= (True, PE_Basic (BVI int_string), pState)\ntrySimplePatternT (StringToken string) pState\n\t= (True, PE_Basic (BVS string), pState)\ntrySimplePatternT (BoolToken bool) pState\n\t= (True, PE_Basic (BVB bool), pState)\ntrySimplePatternT (CharToken char) pState\n\t= (True, PE_Basic (BVC char), pState)\ntrySimplePatternT (RealToken real) pState\n\t= (True, PE_Basic (BVR real), pState)\ntrySimplePatternT (QualifiedIdentToken module_name ident_name) pState\n\t| not (isLowerCaseName ident_name)\n\t\t# (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Expression pState\n\t\t= (True, PE_QualifiedIdent module_id ident_name, pState)\ntrySimplePatternT WildCardToken pState\n\t= (True, PE_WildCard, pState)\ntrySimplePatternT token pState\n\t= (False, PE_Empty, tokenBack pState)\n\ntrySimplePatternWithoutDefinitionsT :: !Token !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntrySimplePatternWithoutDefinitionsT (IdentToken name) pState\n\t| not (isLowerCaseName name)\n\t\t# (id, pState) = stringToIdent name IC_Expression pState\n\t\t= (True, PE_Ident id, pState)\ntrySimplePatternWithoutDefinitionsT SquareOpenToken pState\n\t# (list_expr, pState) = wantListPatternWithoutDefinitions pState\n\t= (True, list_expr, pState)\ntrySimplePatternWithoutDefinitionsT OpenToken pState\n\t# (args=:[exp:exps], pState) = want_pattern_list pState\n\t pState = wantToken FunctionContext \"pattern list\" CloseToken pState\n\t| isEmpty exps\n\t\t= case exp of\n\t\t\tPE_Ident id\n\t\t\t\t-> (True, PE_List [exp], pState)\n\t\t\t_\n\t\t\t\t-> (True, exp, pState)\n\t\t= (True, PE_Tuple args, pState)\nwhere\n\twant_pattern_list pState\n\t\t# (expr, pState) = wantPatternWithoutDefinitions pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (exprs, pState) = want_pattern_list pState\n\t\t\t= ([expr : exprs], pState)\n\t\t\t= ([expr], tokenBack pState)\ntrySimplePatternWithoutDefinitionsT CurlyOpenToken pState\n\t# (rec_or_aray_exp, pState) = wantRecordPatternWithoutDefinitions pState \n\t= (True, rec_or_aray_exp, pState)\ntrySimplePatternWithoutDefinitionsT (IntToken int_string) pState\n\t# (ok,int) = string_to_int int_string\n\t| ok\n\t\t= (True, PE_Basic (BVInt int), pState)\n\t\t= (True, PE_Basic (BVI int_string), pState)\ntrySimplePatternWithoutDefinitionsT (StringToken string) pState\n\t= (True, PE_Basic (BVS string), pState)\ntrySimplePatternWithoutDefinitionsT (BoolToken bool) pState\n\t= (True, PE_Basic (BVB bool), pState)\ntrySimplePatternWithoutDefinitionsT (CharToken char) pState\n\t= (True, PE_Basic (BVC char), pState)\ntrySimplePatternWithoutDefinitionsT (RealToken real) pState\n\t= (True, PE_Basic (BVR real), pState)\ntrySimplePatternWithoutDefinitionsT (QualifiedIdentToken module_name ident_name) pState\n\t| not (isLowerCaseName ident_name)\n\t\t# (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Expression pState\n\t\t= (True, PE_QualifiedIdent module_id ident_name, pState)\ntrySimplePatternWithoutDefinitionsT WildCardToken pState\n\t= (True, PE_WildCard, pState)\ntrySimplePatternWithoutDefinitionsT token pState\n\t= (False, PE_Empty, tokenBack pState)\n\ntrySimpleExpressionT :: !Token !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntrySimpleExpressionT (IdentToken name) pState\n\t# (id, pState) = stringToIdent name IC_Expression pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == GenericOpenToken\n\t\t# (kind, pState) = wantKind pState\t\n\t\t= (True, PE_Generic id kind, pState)\n\t\t= (True, PE_Ident id, tokenBack pState)\ntrySimpleExpressionT SquareOpenToken pState\n\t# (list_expr, pState) = wantListExp cIsNotAPattern pState\n\t= (True, list_expr, pState)\ntrySimpleExpressionT OpenToken pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCloseToken\n\t\t\t#! unit_cons_ident = predefined_idents.[PD_UnitConsSymbol]\n\t\t\t-> (True,PE_Ident unit_cons_ident,pState)\n\t\t_\n\t\t\t# (args=:[exp:exps], pState) = want_expression_list_t token pState\n\t\t\t pState = wantToken FunctionContext \"expression list\" CloseToken pState\n\t\t\t| isEmpty exps\n\t\t\t\t-> case exp of\n\t\t\t\t\tPE_Ident id\n\t\t\t\t\t\t-> (True, PE_List [exp], pState)\n\t\t\t\t\t_\n\t\t\t\t\t\t-> (True, exp, pState)\n\t\t\t\t-> (True, PE_Tuple args, pState)\nwhere\n\twant_expression_list_t token pState\n\t\t# (expr, pState)\n\t\t\t= case token of\n\t\t\t\tCharListToken charList\n\t\t\t\t\t \/\/ To produce a better error message\n\t\t\t\t\t->\tcharListError charList pState\n\t\t\t\t_\n\t\t\t\t\t-> wantExpressionT token pState\n\t\t= want_expression_list_rest expr pState\n\n\twant_expression_list pState\n\t\t# (expr, pState) = wantExpression pState\n\t\t= want_expression_list_rest expr pState\n\n\twant_expression_list_rest expr pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (exprs, pState) = want_expression_list pState\n\t\t\t= ([expr : exprs], pState)\n\t\t\t= ([expr], tokenBack pState)\ntrySimpleExpressionT CurlyOpenToken pState\n\t# (rec_or_aray_exp, pState) = wantRecordOrArrayExp cIsNotAPattern pState \n\t= (True, rec_or_aray_exp, pState)\ntrySimpleExpressionT (IntToken int_string) pState\n\t# (ok,int) = string_to_int int_string\n\t| ok\n\t\t= (True, PE_Basic (BVInt int), pState)\n\t\t= (True, PE_Basic (BVI int_string), pState)\ntrySimpleExpressionT (StringToken string) pState\n\t= (True, PE_Basic (BVS string), pState)\ntrySimpleExpressionT (BoolToken bool) pState\n\t= (True, PE_Basic (BVB bool), pState)\ntrySimpleExpressionT (CharToken char) pState\n\t= (True, PE_Basic (BVC char), pState)\ntrySimpleExpressionT (RealToken real) pState\n\t= (True, PE_Basic (BVR real), pState)\ntrySimpleExpressionT (QualifiedIdentToken module_name ident_name) pState\n\t# (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Expression pState\n\t= (True, PE_QualifiedIdent module_id ident_name, pState)\ntrySimpleExpressionT token pState\n\t= trySimpleNonLhsExpressionT token pState\n\nstring_to_int s\n\t| len==0\n\t\t= (False,0)\n\t| s.[0] == '-'\n\t\t| len>2 && s.[1]=='0' \/* octal *\/\n\t\t\t= (False,0)\n\t\t\t# (ok,int) = (string_to_int2 1 0 s)\n\t\t\t=\t(ok,~int)\n\t| s.[0] == '+'\n\t\t| len>2&& s.[1]=='0' \/* octal *\/\n\t\t\t= (False,0)\n\t\t\t=\tstring_to_int2 1 0 s\n\t| s.[0]=='0' && len>1 \/* octal *\/\n\t\t= (False,0)\n\t\t=\tstring_to_int2 0 0 s\n where\n\tlen = size s\n\n\tstring_to_int2:: !Int !Int !{#Char} -> (!Bool,!Int)\n\tstring_to_int2 posn val s\n\t\t| len==posn\n\t\t\t= (True,val)\n\t\t# n =\ttoInt (s.[posn]) - toInt '0'\n\t\t|\t0<=n && n<= 9\n\t\t\t=\tstring_to_int2 (posn+1) (n+val*10) s\n\t\t\t=\t(False,0)\n\ntrySimpleNonLhsExpressionT :: !Token *ParseState -> *(!Bool,!ParsedExpr,!*ParseState)\ntrySimpleNonLhsExpressionT BackSlashToken pState\n\t# (lam_ident, pState)\t= internalIdent (toString backslash) pState\n\t (file_name, line_nr, pState)\n\t \t\t\t\t\t\t= getFileAndLineNr pState\n\t position\t\t\t\t= FunPos file_name line_nr lam_ident.id_name\n\t (lam_args, pState) \t= wantList \"arguments\" trySimplePattern pState\n\t (token, pState)\t\t= nextToken FunctionContext pState\n\t= case token of\n\t\tDotToken\n\t\t\t# (file_name, line_nr, pState) = getFileAndLineNr pState\n\t\t\t (expr, pState) = wantExpression pState\n\t\t\t ewl = {ewl_nodes = [], ewl_expr = expr, ewl_locals = LocalParsedDefs [], ewl_position = LinePos file_name line_nr}\n\t\t\t rhs = {rhs_alts = UnGuardedExpr ewl, rhs_locals = LocalParsedDefs []}\n\t\t\t-> (True, PE_Lambda lam_ident lam_args rhs position, pState)\n\t\t_\n\t\t \t# (rhs, defining_symbol, pState)\n\t\t\t \t\t\t\t\t\t= wantRhs_without_where token True RhsDefiningSymbolCase pState\n\t\t\t-> (True, PE_Lambda lam_ident lam_args rhs position, pState)\ntrySimpleNonLhsExpressionT (LetToken strict) pState \/\/ let! is not supported in Clean 2.0\n\t| strict\t\t\t\t= (False, PE_Empty, parseError \"Expression\" No \"let! (strict let) not supported in this version of Clean, expression\" pState)\n\t\/\/ otherwise\n\t# (let_binds, pState)\t= wantLocals pState\n\t pState\t\t\t\t= wantToken FunctionContext \"let expression\" InToken pState\n\t (let_expr, pState)\t= wantExpression pState\n\t= (True, PE_Let let_binds let_expr, pState)\ntrySimpleNonLhsExpressionT CaseToken pState\n \t# (case_exp, pState)\t\t= wantCaseExp pState\n\t= (True, case_exp, pState)\ntrySimpleNonLhsExpressionT IfToken pState\n\t# (if_ident, pState) \t\t= internalIdent \"_if\" pState\n \t (cond_exp, pState)\t\t= want_simple_expression \"condition of if\" pState\n \t (then_exp, pState)\t\t= want_simple_expression \"then-part of if\" pState\n \t (else_exp, pState)\t\t= want_simple_expression \"else-part of if\" pState\n\t= (True, PE_If if_ident cond_exp then_exp else_exp, pState)\nwhere\n\twant_simple_expression error pState\n\t\t# (succ, expr, pState) = tryExtendedSimpleExpression pState\n\t\t| succ\n\t\t\t= (expr, pState)\n\t\t\t= (PE_Empty, parseError error No \"\" pState)\ntrySimpleNonLhsExpressionT token pState\n\t= (False, PE_Empty, tokenBack pState)\n\nwantListPatternWithoutDefinitions :: !ParseState -> (ParsedExpr, !ParseState)\nwantListPatternWithoutDefinitions pState\n\t# pState=appScanState setNoNewOffsideForSeqLetBit pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t# pState=appScanState clearNoNewOffsideForSeqLetBit pState\t\n\t# (head_strictness,token,pState) = want_head_strictness token pState\n\t| token==ExclamationToken && (head_strictness<>HeadOverloaded && head_strictness<>HeadUnboxedAndTailStrict)\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token==SquareCloseToken\n\t\t\t= (makeTailStrictNilExpression head_strictness cIsAPattern,pState)\n\t\t\t= (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t| token==SquareCloseToken\n\t\t| head_strictness==HeadUnboxedAndTailStrict\n\t\t\t= (makeTailStrictNilExpression HeadUnboxed cIsAPattern,pState)\n\t\t| head_strictness==HeadStrict\n\t\t\t# (tail_strict,pState) = is_tail_strict_list_or_nil pState\n\t\t\t| tail_strict\n\t\t\t\t= (makeTailStrictNilExpression HeadLazy cIsAPattern,pState)\n\t\t\t\t= (makeNilExpression head_strictness cIsAPattern,pState)\n\t\t\t= (makeNilExpression head_strictness cIsAPattern,pState)\n\t| head_strictness==HeadUnboxedAndTailStrict\n\t\t= (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t| head_strictness==HeadLazy && (case token of (IdentToken \"!!\") -> True; _ -> False)\n\t\t# (next_token,pState) = nextToken FunctionContext pState\n\t\t| next_token==SquareCloseToken\n\t\t\t= (makeTailStrictNilExpression HeadStrict cIsAPattern,pState)\n\t\t\t= want_LGraphExpr token [] head_strictness (tokenBack pState)\n\t\t= want_LGraphExpr token [] head_strictness pState\n\twhere\n\t\twant_LGraphExpr token acc head_strictness pState\n\t\t\t= case token of\n\t\t\t\tCharListToken chars\n\t\t\t\t\t->\twant_list (add_chars (fromString chars) acc) pState\n\t\t\t\t_\t#\t(exp, pState) = wantPatternWithoutDefinitionsT token pState\n\t\t\t\t\t->\twant_list [exp: acc] pState\n\t\twhere\n\t\t\twant_list acc pState\n\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t= case token of\n\t\t\t\t\tSquareCloseToken\n\t\t\t\t\t\t#\tnil_expr = makeNilExpression head_strictness cIsAPattern\n\t\t\t\t\t\t->\t(gen_pattern_cons_nodes acc nil_expr head_strictness,pState)\n\t\t\t\t\tExclamationToken\n\t\t\t\t\t\t| head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t| token==SquareCloseToken\n\t\t\t\t\t\t\t\t# nil_expr = makeTailStrictNilExpression head_strictness cIsAPattern\n\t\t\t\t\t\t\t\t->\t(gen_pattern_tail_strict_cons_nodes acc nil_expr head_strictness,pState)\n\t\t\t\t\t\t\t\t-> (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t\t\t\t\tCommaToken\n\t\t\t\t\t\t#\t(token, pState)\t= nextToken FunctionContext pState\n\t\t\t\t\t\t->\twant_LGraphExpr token acc head_strictness pState\n\t\t\t\t\tColonToken\n\t\t\t\t\t\t# (exp, pState)\t\t= wantPatternWithoutDefinitions pState\n\t\t\t\t\t\t# (token,pState)\t= nextToken FunctionContext pState\n\t\t\t\t\t\t| token==SquareCloseToken\n\t\t\t\t\t\t\t-> (gen_pattern_cons_nodes acc exp head_strictness,pState)\n\t\t\t\t\t\t| token==ExclamationToken && head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t# pState = wantToken FunctionContext \"list\" SquareCloseToken pState\n\t\t\t\t\t\t\t-> (gen_pattern_tail_strict_cons_nodes acc exp head_strictness,pState)\n\t\t\t\t\t\t| token==ColonToken \/\/ to allow [1:2:[]] etc.\n\t\t\t\t\t\t\t-> want_list [exp:acc] (tokenBack pState)\n\t\t\t\t\t\t\t# pState = parseError \"list\" (Yes token) \"] or :\" pState\n\t\t\t\t\t\t\t-> (gen_pattern_cons_nodes acc exp head_strictness,pState)\n\t\t\t\t\tDotDotToken\n\t\t\t\t\t\t->\t(PE_Empty, parseError \"want list expression\" No \"No dot dot expression in a pattern\" pState)\n\t\t\t\t\tDoubleBackSlashToken\n\t\t\t\t\t\t->\t(PE_Empty, parseError \"want list expression\" No \"No \\\\\\\\ expression in a pattern\" pState)\n\t\t\t\t\t_\n\t\t\t\t\t\t#\tnil_expr = makeNilExpression head_strictness cIsAPattern\n\t\t\t\t\t\t\tpState\t= parseError \"list\" (Yes token) \"list element separator\" pState\n\t\t\t\t\t\t->\t(gen_pattern_cons_nodes acc nil_expr head_strictness,pState)\n\ngen_pattern_cons_nodes [] exp head_strictness\n\t= exp\ngen_pattern_cons_nodes l exp head_strictness\n\t= gen_pattern_cons_nodes l exp\nwhere\n\tcons_ident_exp = makeConsIdentExpression head_strictness cIsAPattern\n\t\n\tgen_pattern_cons_nodes [e:r] exp\n\t\t= gen_pattern_cons_nodes r (PE_List [cons_ident_exp,e,exp])\n\tgen_pattern_cons_nodes [] exp\n\t\t= exp\n\ngen_pattern_tail_strict_cons_nodes [] exp head_strictness\n\t= exp\ngen_pattern_tail_strict_cons_nodes r exp head_strictness\n\t= gen_pattern_tail_strict_cons_nodes r exp\nwhere\n\ttail_strict_cons_ident_exp = makeTailStrictConsIdentExpression head_strictness cIsAPattern\n\t\n\tgen_pattern_tail_strict_cons_nodes [e:r] exp\n\t\t= gen_pattern_tail_strict_cons_nodes r (PE_List [tail_strict_cons_ident_exp,e,exp])\n\tgen_pattern_tail_strict_cons_nodes [] exp\n\t\t= exp\n\nwantListExp :: !Bool !ParseState -> (ParsedExpr, !ParseState)\nwantListExp is_pattern pState\n\t# pState=appScanState setNoNewOffsideForSeqLetBit pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t# pState=appScanState clearNoNewOffsideForSeqLetBit pState\t\n\t# (head_strictness,token,pState) = want_head_strictness token pState\n\t| token==ExclamationToken && (head_strictness<>HeadOverloaded && head_strictness<>HeadUnboxedAndTailStrict)\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token==SquareCloseToken\n\t\t\t= (makeTailStrictNilExpression head_strictness is_pattern,pState)\n\t\t\t= (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t| token==SquareCloseToken\n\t\t| head_strictness==HeadUnboxedAndTailStrict\n\t\t\t= (makeTailStrictNilExpression HeadUnboxed is_pattern,pState)\n\t\t| head_strictness==HeadStrict\n\t\t\t# (tail_strict,pState) = is_tail_strict_list_or_nil pState\n\t\t\t| tail_strict\n\t\t\t\t= (makeTailStrictNilExpression HeadLazy is_pattern,pState)\n\t\t\t\t= (makeNilExpression head_strictness is_pattern,pState)\n\t\t\t= (makeNilExpression head_strictness is_pattern,pState)\n\t| head_strictness==HeadUnboxedAndTailStrict\n\t\t= (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t| head_strictness==HeadLazy && (case token of (IdentToken \"!!\") -> True; _ -> False)\n\t\t# (next_token,pState) = nextToken FunctionContext pState\n\t\t| next_token==SquareCloseToken\n\t\t\t= (makeTailStrictNilExpression HeadStrict is_pattern,pState)\n\t\t\t= want_LGraphExpr token [] head_strictness (tokenBack pState)\n\t\t= want_LGraphExpr token [] head_strictness pState\n\twhere\n\t\twant_LGraphExpr token acc head_strictness pState\n\t\t\t= case token of\n\t\t\t\tCharListToken chars\n\t\t\t\t\t->\twant_list (add_chars (fromString chars) acc) pState\n\t\t\t\t_\t#\t(exp, pState) = (if is_pattern (wantPatternT token) (wantExpressionT token)) pState\n\t\t\t\t\t->\twant_list [exp: acc] pState\n\t\twhere\n\t\t\twant_list acc pState\n\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t= case token of\n\t\t\t\t\tSquareCloseToken\n\t\t\t\t\t\t#\tnil_expr = makeNilExpression head_strictness is_pattern\n\t\t\t\t\t\t->\t(gen_cons_nodes acc nil_expr,pState)\n\t\t\t\t\tExclamationToken\n\t\t\t\t\t\t| head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t| token==SquareCloseToken\n\t\t\t\t\t\t\t\t# nil_expr = makeTailStrictNilExpression head_strictness is_pattern\n\t\t\t\t\t\t\t\t->\t(gen_tail_strict_cons_nodes acc nil_expr,pState)\n\t\t\t\t\t\t\t\t-> (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t\t\t\t\tCommaToken\n\t\t\t\t\t\t#\t(token, pState)\t= nextToken FunctionContext pState\n\t\t\t\t\t\t->\twant_LGraphExpr token acc head_strictness pState\n\t\t\t\t\tColonToken\n\t\t\t\t\t\t# (exp, pState)\t\t= wantExpressionOrPattern is_pattern pState\n\t\t\t\t\t\t# (token,pState)\t= nextToken FunctionContext pState\n\t\t\t\t\t\t| token==SquareCloseToken\n\t\t\t\t\t\t\t-> (gen_cons_nodes acc exp,pState)\n\t\t\t\t\t\t| token==ExclamationToken && head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t# pState = wantToken FunctionContext \"list\" SquareCloseToken pState\n\t\t\t\t\t\t\t-> (gen_tail_strict_cons_nodes acc exp,pState)\n\t\t\t\t\t\t| token==ColonToken \/\/ to allow [1:2:[]] etc.\n\t\t\t\t\t\t\t-> want_list [exp:acc] (tokenBack pState)\n\t\t\t\t\t\t\t# pState = parseError \"list\" (Yes token) \"] or :\" pState\n\t\t\t\t\t\t\t-> (gen_cons_nodes acc exp,pState)\n\t\t\t\t\tDotDotToken\n\t\t\t\t\t\t| is_pattern\n\t\t\t\t\t\t->\t(PE_Empty, parseError \"want list expression\" No \"No dot dot expression in a pattern\" pState)\n\t\t\t\t\t\t| length acc > 2 || isEmpty acc\n\t\t\t\t\t\t#\tnil_expr = makeNilExpression head_strictness is_pattern\n\t\t\t\t\t\t\tpState\t\t\t\t= parseError \"list expression\" No \"one or two expressions before ..\" pState\n\t\t\t\t\t\t->\t(gen_cons_nodes acc nil_expr,pState)\n\t\t\t\t\t\t#\t(token, pState)\t\t= nextToken FunctionContext pState\n\t\t\t\t\t\t->\tcase token of\n\t\t\t\t\t\t\t SquareCloseToken\n\t\t\t\t\t\t\t\t->\tcase acc of\n\t\t\t\t\t\t\t\t\t\t[e]\n\t\t\t\t\t\t\t\t\t\t\t# pd_from_index =\n\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromS\n\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromU\n\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadOverloaded) PD_FromO\n\t\t\t\t\t\t\t\t\t\t\t\t\tPD_From))\n\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_From pd_from_index e), pState)\n\t\t\t\t\t\t\t\t\t\t[e2,e1]\n\t\t\t\t\t\t\t\t\t\t\t# pd_from_then_index =\n\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromThenS\n\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromThenU\n\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadOverloaded) PD_FromThenO\n\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromThen))\n\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromThen pd_from_then_index e1 e2), pState)\n\t\t\t\t\t\t\t\t\t\t_\t-> abort \"Error 1 in WantListExp\"\n\t\t\t\t\t\t\t ExclamationToken\n\t\t\t\t\t\t\t\t| head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t\t\t# pState = wantToken FunctionContext \"dot dot expression\" SquareCloseToken pState\n\t\t\t\t\t\t\t\t\t->\tcase acc of\n\t\t\t\t\t\t\t\t\t\t\t[e]\n\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromSTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromUTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromTS)\n\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_From pd_from_index e), pState)\n\t\t\t\t\t\t\t\t\t\t\t[e2,e1]\n\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_then_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromThenSTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromThenUTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromThenTS)\n\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromThen pd_from_then_index e1 e2), pState)\n\t\t\t\t\t\t\t\t\t\t\t_\t-> abort \"Error 2 in WantListExp\"\n\t\t\t\t\t\t\t _\t#\t(exp, pState)\t= wantExpressionT token pState\n\t\t\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t\t-> case token of\n\t\t\t\t\t\t\t\t\tSquareCloseToken\n\t\t\t\t\t\t\t\t\t\t->\tcase acc of\n\t\t\t\t\t\t\t\t\t\t\t[e]\n\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_to_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromToS\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromToU\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadOverloaded) PD_FromToO\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromTo))\n\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromTo pd_from_to_index e exp), pState)\n\t\t\t\t\t\t\t\t\t\t\t[e2,e1]\n\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_then_to_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromThenToS\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromThenToU\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadOverloaded) PD_FromThenToO\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromThenTo))\n\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromThenTo pd_from_then_to_index e1 e2 exp), pState)\n\t\t\t\t\t\t\t\t\t\t\t_\t-> abort \"Error 3 in WantListExp\"\n\t\t\t\t\t\t\t\t\tExclamationToken\n\t\t\t\t\t\t\t\t\t\t| head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t\t\t\t\t# pState = wantToken FunctionContext \"dot dot expression\" SquareCloseToken pState\n\t\t\t\t\t\t\t\t\t\t\t->\tcase acc of\n\t\t\t\t\t\t\t\t\t\t\t\t\t[e]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_to_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromToSTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromToUTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromToTS)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromTo pd_from_to_index e exp), pState)\n\t\t\t\t\t\t\t\t\t\t\t\t\t[e2,e1]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_then_to_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromThenToSTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromThenToUTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromThenToTS)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromThenTo pd_from_then_to_index e1 e2 exp), pState)\n\t\t\t\t\t\t\t\t\t\t\t\t\t_\t-> abort \"Error 4 in WantListExp\"\n\t\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t\t-> (PE_Empty, parseError \"dot dot expression\" (Yes token) \"] or !]\" pState)\n\t\t\t\t\tDoubleBackSlashToken\n\t\t\t\t\t\t| is_pattern\n\t\t\t\t\t\t->\t(PE_Empty, parseError \"want list expression\" No \"No \\\\\\\\ expression in a pattern\" pState)\n\t\t\t\t\t\t| length acc == 1\n\t\t\t\t\t\t->\twantListComprehension head_strictness (acc!!0) pState\n\t\t\t\t\t\t\/\/ otherwise \/\/ length acc <> 1\n\t\t\t\t\t\t#\tnil_expr = makeNilExpression head_strictness is_pattern\n\t\t\t\t\t\t\tpState\t\t\t\t= parseError \"list comprehension\" No \"one expressions before \\\\\\\\\" pState\n\t\t\t\t\t\t->\t(gen_cons_nodes acc nil_expr,pState)\n\t\t\t\t\t_\t#\tnil_expr = makeNilExpression head_strictness is_pattern\n\t\t\t\t\t\t\tpState\t= parseError \"list\" (Yes token) \"list element separator\" pState\n\t\t\t\t\t\t->\t(gen_cons_nodes acc nil_expr,pState)\n\t\t\t\n\t\t\tgen_cons_nodes [] exp\n\t\t\t\t= exp\n\t\t\tgen_cons_nodes l exp\n\t\t\t\t= gen_cons_nodes l exp\n\t\t\twhere\n\t\t\t\tcons_ident_exp = makeConsIdentExpression head_strictness is_pattern\n\t\t\t\t\n\t\t\t\tgen_cons_nodes [e:r] exp\n\t\t\t\t\t= gen_cons_nodes r (PE_List [cons_ident_exp,e,exp])\n\t\t\t\tgen_cons_nodes [] exp\n\t\t\t\t\t= exp\n\n\t\t\tgen_tail_strict_cons_nodes [] exp\n\t\t\t\t= exp\n\t\t\tgen_tail_strict_cons_nodes r exp\n\t\t\t\t= gen_tail_strict_cons_nodes r exp\n\t\t\twhere\n\t\t\t\ttail_strict_cons_ident_exp = makeTailStrictConsIdentExpression head_strictness is_pattern\n\t\t\t\t\n\t\t\t\tgen_tail_strict_cons_nodes [e:r] exp\n\t\t\t\t\t= gen_tail_strict_cons_nodes r (PE_List [tail_strict_cons_ident_exp,e,exp])\n\t\t\t\tgen_tail_strict_cons_nodes [] exp\n\t\t\t\t\t= exp\n\nwant_head_strictness :: Token *ParseState -> *(!Int,!Token,!*ParseState)\nwant_head_strictness ExclamationToken pState\n\t# (token,pState) = nextToken FunctionContext pState\n\t= (HeadStrict,token,pState)\nwant_head_strictness (SeqLetToken strict) pState\n\t# (token,pState) = nextToken FunctionContext pState\n\t| strict\n\t\t= (HeadUnboxedAndTailStrict,token,pState);\n\t\t= (HeadUnboxed,token,pState)\nwant_head_strictness BarToken pState\n\t# (token,pState) = nextToken FunctionContext pState\n\t= (HeadOverloaded,token,pState)\nwant_head_strictness token pState\n\t= (HeadLazy,token,pState)\n\nadd_chars [] \t\t\tacc\t= acc\nadd_chars ['\\\\',c1,c2,c3:r] acc\n\t| c1>='0' && c1<='7'\n\t\t= add_chars r [PE_Basic (BVC (toString ['\\'','\\\\',c1,c2,c3,'\\''])): acc]\nadd_chars ['\\\\',c:r] acc = add_chars r [PE_Basic (BVC (toString ['\\'','\\\\',c,'\\''])): acc]\nadd_chars [c:r] \t\tacc\t= add_chars r [PE_Basic (BVC (toString ['\\'',c,'\\''])): acc]\n\nmakeNilExpression :: Int Bool -> ParsedExpr\nmakeNilExpression head_strictness is_pattern\n\t# pre_def_nil_index= if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_NilSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictNilSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadOverloaded)\n\t\t\t\t\t\t\t(if is_pattern PD_OverloadedNilSymbol PD_nil)\n\t\t\t\t\t\t\t(if is_pattern PD_UnboxedNilSymbol PD_nil_u)))\n\t#! nil_ident = predefined_idents.[pre_def_nil_index]\n\t= PE_Ident nil_ident\n\nmakeTailStrictNilExpression :: Int Bool -> ParsedExpr\nmakeTailStrictNilExpression head_strictness is_pattern\n\t# pre_def_nil_index= if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_TailStrictNilSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictTailStrictNilSymbol\n\t\t\t\t\t\t\t(if is_pattern PD_UnboxedTailStrictNilSymbol PD_nil_uts))\n\t#! nil_ident = predefined_idents.[pre_def_nil_index]\n\t= PE_Ident nil_ident\n\nmakeConsIdentExpression :: Int Bool -> ParsedExpr\nmakeConsIdentExpression head_strictness is_pattern\n\t# pre_def_cons_index=if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_ConsSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictConsSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadOverloaded)\n\t\t\t\t\t\t\t(if is_pattern PD_OverloadedConsSymbol PD_cons)\n\t\t\t\t\t\t\t(if is_pattern PD_UnboxedConsSymbol PD_cons_u)))\n\t#! cons_ident = predefined_idents.[pre_def_cons_index]\n\t= PE_Ident cons_ident\n\ncons_and_nil_symbol_index HeadLazy = (PD_ConsSymbol,PD_NilSymbol)\ncons_and_nil_symbol_index HeadStrict = (PD_StrictConsSymbol,PD_StrictNilSymbol)\ncons_and_nil_symbol_index HeadUnboxed = (PD_cons_u,PD_nil_u)\ncons_and_nil_symbol_index HeadOverloaded = (PD_cons,PD_nil)\n\nmakeTailStrictConsIdentExpression :: Int Bool -> ParsedExpr\nmakeTailStrictConsIdentExpression head_strictness is_pattern\n\t# pre_def_cons_index=if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_TailStrictConsSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictTailStrictConsSymbol\n\t\t\t\t\t\t\t(if is_pattern PD_UnboxedTailStrictConsSymbol PD_cons_uts))\n\t#! cons_ident = predefined_idents.[pre_def_cons_index]\n\t= PE_Ident cons_ident\n\ntail_strict_cons_and_nil_symbol_index HeadLazy = (PD_TailStrictConsSymbol,PD_TailStrictNilSymbol)\ntail_strict_cons_and_nil_symbol_index HeadStrict = (PD_StrictTailStrictConsSymbol,PD_StrictTailStrictNilSymbol)\ntail_strict_cons_and_nil_symbol_index HeadUnboxed = (PD_cons_uts,PD_nil_uts)\n\n\/*\n\t(List and Array) Comprehensions\n*\/\n\nwantArrayComprehension :: !ArrayKind !ParsedExpr !ParseState -> (!ParsedExpr, !ParseState)\nwantArrayComprehension array_kind exp pState\n\t# (qualifiers, pState) = wantQualifiers pState\n\t= (PE_ArrayCompr array_kind exp qualifiers, wantToken FunctionContext \"array comprehension\" CurlyCloseToken pState)\n\nwantListComprehension :: !Int !ParsedExpr !ParseState -> (!ParsedExpr, !ParseState)\nwantListComprehension head_strictness exp pState\n\t# (qualifiers, pState) = wantQualifiers pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token==SquareCloseToken\n\t\t# (cons_index,nil_index) = cons_and_nil_symbol_index head_strictness\n\t\t= (PE_ListCompr cons_index nil_index exp qualifiers, pState)\n\t| token==ExclamationToken && head_strictness<>HeadOverloaded\n\t\t# pState = wantToken FunctionContext \"list comprehension\" SquareCloseToken pState\n\t\t# (tail_strict_cons_index,tail_strict_nil_index) = tail_strict_cons_and_nil_symbol_index head_strictness\n\t\t= (PE_ListCompr tail_strict_cons_index tail_strict_nil_index exp qualifiers, pState)\n\t\t# pState = parseError \"list\" (Yes token) (toString SquareCloseToken) pState\n\t\t# (cons_index,nil_index) = cons_and_nil_symbol_index head_strictness\n\t\t= (PE_ListCompr cons_index nil_index exp qualifiers, pState)\n\nwantQualifiers :: !ParseState -> (![Qualifier], !ParseState)\nwantQualifiers pState\n\t# (qual, pState) = want_qualifier pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == CommaToken\n\t\t# (quals, pState) = wantQualifiers pState\n\t\t= ([qual : quals], pState)\n\t\t= ([qual], tokenBack pState)\nwhere\n\twant_qualifier :: !ParseState -> (!Qualifier, !ParseState)\n\twant_qualifier pState\n\t\t# (qual_position, pState) = getPosition pState\n\t\t (qual_filename, pState) = accScanState getFilename pState\n\t\t (lhs_expr, pState) = wantPattern pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| token == LeftArrowToken\n\t\t\t= want_generators IsListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState\n\t\t| token == LeftArrowColonToken\n\t\t\t= want_generators IsArrayGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState\n\t\t| token == LeftArrowWithBarToken\n\t\t\t= want_generators IsOverloadedListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState\n\t\t\t= ({qual_generators = [], qual_let_defs=LocalParsedDefs [], qual_filter = No, qual_position = {lc_line = 0, lc_column = 0}, qual_filename = \"\" },\n\t\t\t\t\tparseError \"comprehension: qualifier\" (Yes token) \"qualifier(s)\" pState)\n\n\twant_generators :: !GeneratorKind !LineAndColumn !FileName !ParsedExpr !ParseState -> (!Qualifier, !ParseState)\n\twant_generators gen_kind qual_position qual_filename pattern_exp pState\n\t\t# (gen_position, pState)\t\t\t= getPosition pState\n\t\t# (gen_expr, pState) = wantExpression pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t generator = { gen_kind = gen_kind, gen_expr = gen_expr, gen_pattern = pattern_exp,\n\t\t\t\t\t\tgen_position = toLineAndColumn gen_position }\n\t\t| token == AndToken\n\t\t\t# (qualifier, pState) = want_qualifier pState\n\t\t\t= ({qualifier & qual_generators = [ generator : qualifier.qual_generators] }, pState)\n\t\t\t# (let_defs,filter,pState)= parse_optional_lets_and_filter token pState\n\t\t\t= ( {qual_generators = [generator], qual_let_defs=let_defs, qual_filter = filter, qual_position = qual_position, qual_filename = qual_filename}\n\t\t\t ,\tpState )\n\n\tparse_optional_lets_and_filter :: !Token !ParseState -> (!LocalDefs,!Optional ParsedExpr,!ParseState)\n\tparse_optional_lets_and_filter BarToken pState\n\t\t# (filter_expr, pState) = wantExpression pState\n\t\t= (LocalParsedDefs [], Yes filter_expr,pState)\n\tparse_optional_lets_and_filter CommaToken pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token<>LetToken False\n\t\t\t= (LocalParsedDefs [],No,tokenBack (tokenBack pState))\n\t\t# (locals,pState) = wantLocals pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t# (filter,pState) = parse_optional_filter token pState\n\t\t= (locals,filter,pState);\n\tparse_optional_lets_and_filter token pState\n\t\t= (LocalParsedDefs [], No,tokenBack pState)\n\n\tparse_optional_filter :: !Token !ParseState -> (!Optional ParsedExpr,!ParseState)\n\tparse_optional_filter BarToken pState\n\t\t# (filter_expr, pState) = wantExpression pState\n\t\t= (Yes filter_expr,pState)\n\tparse_optional_filter token pState\n\t\t= (No,tokenBack pState)\n\n\/**\n\tCase Expressions\n**\/\n\nwantCaseExp :: !ParseState -> (ParsedExpr, !ParseState)\nwantCaseExp pState\n\t# (case_ident, pState) = internalIdent \"_c\" pState\n\t (case_exp, pState)\t= wantExpression pState\n\t pState\t\t\t\t= wantToken FunctionContext \"case expression\" OfToken pState\n\t pState\t\t\t\t= wantBeginGroup \"case\" pState\n\t (case_alts, (definingSymbol,pState))\n\t \t\t\t\t\t\t= parseList tryCaseAlt (RhsDefiningSymbolCase, pState)\n\t (found, alt, pState)\t= tryLastCaseAlt definingSymbol pState\n\t| found\n\t\t= (PE_Case case_ident case_exp (case_alts++[alt]), wantEndCase pState)\n\t\t= (PE_Case case_ident case_exp case_alts, wantEndCase pState)\nwhere\n\ttryCaseAlt :: (!RhsDefiningSymbol, !ParseState) -> (!Bool, CaseAlt, (!RhsDefiningSymbol, !ParseState))\n\ttryCaseAlt (definingSymbol, pState)\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t# (fname,linenr,pState) = getFileAndLineNr pState\n\t\t# (succ, pattern, pState) = try_pattern token pState\n\t\t| succ\n\t\t\t# (rhs, definingSymbol, pState) = wantRhs True definingSymbol pState\n\t\t\t= (True, { calt_pattern = pattern, calt_rhs = rhs, calt_position=LinePos fname linenr }, (definingSymbol, pState))\n\t\t\/\/ otherwise \/\/ ~ succ\n\t\t\t= (False, abort \"no case alt\", (definingSymbol, pState))\n\t\n\ttryLastCaseAlt :: !RhsDefiningSymbol !ParseState -> (!Bool, CaseAlt, !ParseState)\n\ttryLastCaseAlt definingSymbol pState\n\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t| isDefiningSymbol definingSymbol token\n\t\t\t# (fname,linenr,pState) = getFileAndLineNr pState\n\t\t\t pState\t\t\t= tokenBack pState\n\t\t\t (rhs, _, pState) = wantRhs True definingSymbol pState\n\t\t\t= (True, { calt_pattern = PE_WildCard, calt_rhs = rhs, calt_position=LinePos fname linenr }, pState)\n\t\t| token == OtherwiseToken\n\t\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t\t (fname,linenr,pState) = getFileAndLineNr pState\n\t\t\t pState\t\t\t= tokenBack pState\n\t\t\t| isDefiningSymbol definingSymbol token\n\t\t\t\t# (rhs, _, pState) = wantRhs True definingSymbol pState\n\t\t\t\t= (True, { calt_pattern = PE_WildCard, calt_rhs = rhs, calt_position=LinePos fname linenr }, pState)\n\t\t\t\t= (False, abort \"no case alt\", pState)\n\t\t\t= (False, abort \"no case alt\", tokenBack pState)\n\n\/\/\tcaseSeperator t = t == EqualToken || t == ArrowToken \/\/ to enable Clean 1.3.x case expressions\n\n\t\/\/ FIXME: it would be better if this would use (tryExpression cIsNotPattern)\n\t\/\/ but there's no function tryExpression available yet\n\ttry_pattern :: !Token !ParseState -> (!Bool, ParsedExpr, !ParseState)\n\ttry_pattern token pState\n\t\t# (succ, expr, pState) = trySimplePatternT token pState\n\t\t| succ\n\t\t\t# (succ, expr2, pState) = trySimplePattern pState\n\t\t\t| succ\n\t\t\t\t# (exprs, pState) = parseList trySimplePattern pState\n\t\t\t\t# list = PE_List [expr,expr2 : exprs]\n\t\t\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t\t\t| token == DoubleColonToken\n\t\t\t\t\t# (dyn_type, pState) = wantDynamicTypeInPattern pState\n\t\t\t\t\t= (True, PE_DynamicPattern list dyn_type, pState)\n\t\t\t\t\t= (True, list, tokenBack pState)\n\t\t\t\t= (True, expr, pState)\n\t\t\t= (False, abort \"no expression\", pState)\n\n:: NestedUpdate =\n\t{\tnu_selectors :: ![ParsedSelection]\n\t,\tnu_update_expr :: !ParsedExpr\n\t}\n\nerrorIdent :: Ident\nerrorIdent\n\t=\t{id_name = \"<>\", id_info = nilPtr}\n\nbuildNodeDef :: ParsedExpr ParsedExpr -> ParsedDefinition\nbuildNodeDef lhsExpr rhsExpr\n\t=\tPD_NodeDef NoPos lhsExpr rhs\n\twhere\n\t\trhs\t=\n\t\t\t{ rhs_alts\n\t\t\t\t= UnGuardedExpr\n\t\t\t\t\t{ ewl_nodes\t\t= []\n\t\t\t\t\t, ewl_locals\t= LocalParsedDefs []\n\t\t\t\t\t, ewl_expr\t\t= rhsExpr\n\t\t\t\t\t, ewl_position\t= NoPos\n\t\t\t\t\t}\n\t\t\t, rhs_locals\n\t\t\t\t= LocalParsedDefs []\n\t\t\t}\n\n\/**\n\tRecord expressions\n**\/\n\nwantRecordOrArrayExp :: !Bool !ParseState -> (ParsedExpr, !ParseState)\nwantRecordOrArrayExp is_pattern pState\n\t| is_pattern\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == SquareOpenToken\n\t\t\t# (elems, pState) = want_array_assignments pState\n\t\t\t= (PE_ArrayPattern elems, wantToken FunctionContext \"array selections in pattern\" CurlyCloseToken pState)\n\t\t| token == CurlyCloseToken\n\t\t\t= (PE_Empty, parseError \"record or array pattern\" No \"Array denotation not\" pState)\n\t\t\/\/ otherwise \/\/ is_pattern && token <> SquareOpenToken\n\t\t\t= want_record_pattern token pState\n\t\/\/ otherwise \/\/ ~ is_pattern\n\t# pState=appScanState setNoNewOffsideForSeqLetBit pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t# pState=appScanState clearNoNewOffsideForSeqLetBit pState\n\t= case token of\n\t\tExclamationToken\n\t\t\t-> want_array_elems StrictArray pState\n\t\tSeqLetToken False\n\t\t\t-> want_array_elems UnboxedArray pState\n\t\tCurlyCloseToken\n\t\t\t-> (PE_ArrayDenot OverloadedArray [], pState)\n\t\t_\n\t\t\t# (opt_type, pState) = try_type_specification token pState\n\t\t\t-> case opt_type of\n\t\t\t\tNoRecordName\n\t\t\t\t\t# (succ, field, pState) = try_field_assignment token pState\n\t\t\t\t\t| succ\n\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t| token == CommaToken\n\t\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t (fields, pState) = want_field_assignments cIsNotAPattern token pState\n\t\t\t\t\t\t\t-> (PE_Record PE_Empty NoRecordName [ field : fields ], wantToken FunctionContext \"record or array\" CurlyCloseToken pState)\n\t\t\t\t\t\t| token == CurlyCloseToken\n\t\t\t\t\t\t\t-> (PE_Record PE_Empty NoRecordName [ field ], pState)\n\t\t\t\t\t\t\t-> (PE_Record PE_Empty NoRecordName [ field ], parseError \"record or array\" (Yes token) \"}\" pState)\n\t\t\t\t\t# (expr, pState) = wantExpressionT token pState\n\t\t\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t| token == AndToken\n\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t-> want_record_or_array_update token expr pState\n\t\t\t\t\t| token == DoubleBackSlashToken\n\t\t\t\t\t\t-> wantArrayComprehension OverloadedArray expr pState\n\t\t\t\t\t# (elems, pState) = want_more_array_elems token pState\n\t\t\t\t\t-> (PE_ArrayDenot OverloadedArray [expr : elems], pState)\n\t\t\t\topt_type\n\t\t\t\t\t-> want_record opt_type pState\nwhere\n\twant_array_elems array_kind pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == CurlyCloseToken\n\t\t\t= (PE_ArrayDenot array_kind [], pState)\n\t\t\t# (expr, pState) = wantExpressionT token pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == DoubleBackSlashToken\n\t\t\t\t= wantArrayComprehension array_kind expr pState\n\t\t\t\t# (elems, pState) = want_more_array_elems token pState\n\t\t\t\t= (PE_ArrayDenot array_kind [expr:elems], pState)\n\n\twant_more_array_elems CurlyCloseToken pState\n\t\t= ([], pState)\n\twant_more_array_elems CommaToken pState\n\t\t# (elem, pState) = wantExpression pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t (elems, pState) = want_more_array_elems token pState\n\t\t= ([elem : elems], pState)\n\twant_more_array_elems token pState\n\t\t= ([], parseError \"array elements\" (Yes token) \"\" pState)\n\t\n\twant_record_pattern (IdentToken name) pState\n\t\t| isUpperCaseName name\n\t\t\t# pState = wantToken FunctionContext \"record pattern\" BarToken pState\n\t\t\t (type_id, pState) = stringToIdent name IC_Type pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (fields, pState) = want_field_assignments cIsAPattern token pState\n\t\t\t= (PE_Record PE_Empty (RecordNameIdent type_id) fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState)\n\twant_record_pattern (QualifiedIdentToken module_name record_name) pState\n\t\t| isUpperCaseName record_name\n\t\t\t# pState = wantToken FunctionContext \"record pattern\" BarToken pState\n\t\t\t (module_id, pState) = stringToQualifiedModuleIdent module_name record_name IC_Type pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (fields, pState) = want_field_assignments cIsAPattern token pState\n\t\t\t= (PE_Record PE_Empty (RecordNameQualifiedIdent module_id record_name) fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState) \n\twant_record_pattern token pState\n\t\t# (fields, pState) = want_field_assignments cIsAPattern token pState\n\t\t= (PE_Record PE_Empty NoRecordName fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState) \n\n\ttry_type_specification (IdentToken type_name) pState\n\t\t| isUpperCaseName type_name || isFunnyIdName type_name\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == BarToken\n\t\t\t\t# (type_id, pState) = stringToIdent type_name IC_Type pState\n\t\t\t\t= (RecordNameIdent type_id, pState)\n\t\t\t\t= (NoRecordName, tokenBack pState)\n\t\t\t= (NoRecordName, pState)\n\ttry_type_specification (QualifiedIdentToken module_name record_name) pState\n\t\t| isUpperCaseName record_name || isFunnyIdName record_name\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == BarToken\n\t\t\t\t# (module_ident, pState) = stringToQualifiedModuleIdent module_name record_name IC_Type pState\n\t\t\t\t= (RecordNameQualifiedIdent module_ident record_name, pState)\n\t\t\t\t= (NoRecordName, tokenBack pState)\n\t\t\t= (NoRecordName, pState)\n\ttry_type_specification _ pState\n\t\t= (NoRecordName, pState)\n\nwant_updates :: !OptionalRecordName Token ParseState -> ([NestedUpdate], ParseState)\nwant_updates type token pState\n\t# (updates, pState)\n\t\t= parse_updates token pState\n\/\/ RWS FIXME error message if updates == []\n\t= (updates, pState)\nwhere\n\tparse_updates :: Token ParseState -> ([NestedUpdate], ParseState)\n\tparse_updates token pState\n\t\t# (update, pState) = want_update token pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t (updates, pState) = parse_updates token pState \n\t\t\t= ([update : updates], pState)\n\t\t\/\/ otherwise\n\t\t\t= ([update], tokenBack pState)\n\n\twant_update :: Token ParseState -> (NestedUpdate, ParseState)\n\twant_update token pState\n\t\t# (selectors, token, pState) = wantSelectors token pState\n\t\t| token == EqualToken\n\t\t\t# (expr, pState) = wantExpression pState\n\t\t\t= ({nu_selectors = selectors, nu_update_expr = expr}, pState)\n\t\t\t= ({nu_selectors = selectors, nu_update_expr = PE_Empty}, parseError \"field assignment\" (Yes token) \"=\" pState)\n\ntransform_record_or_array_update :: !OptionalRecordName ParsedExpr [NestedUpdate] !Int ParseState -> (ParsedExpr, ParseState)\ntransform_record_or_array_update type expr updates level pState\n\t| is_record_update sortedUpdates\n\t\t=\ttransform_record_update type expr groupedUpdates level pState\n\t\/\/ otherwise\n\t\t=\ttransform_array_update expr updates level pState\n\twhere\n\t\tsortedUpdates\n\t\t\t\/\/ sort updates by first field name, array updates last\n\t\t\t=\tsortBy smaller_update updates\n\t\t\twhere\n\t\t\t\tsmaller_update :: NestedUpdate NestedUpdate -> Bool\n\t\t\t\tsmaller_update a b\n\t\t\t \t\t=\tsmaller_selector (hd a.nu_selectors) (hd b.nu_selectors)\n\t\t \t\t\twhere\n\t\t\t\t\t\tsmaller_selector :: ParsedSelection ParsedSelection -> Bool\n\t\t\t\t\t\tsmaller_selector (PS_Record ident1 _) (PS_Record ident2 _)\n\t\t\t\t\t\t\t=\tident1.id_name < ident2.id_name\n\t\t\t\t\t\tsmaller_selector (PS_Record ident1 _) (PS_QualifiedRecord _ field_name2 _)\n\t\t\t\t\t\t\t=\tident1.id_name < field_name2\n\t\t\t\t\t\tsmaller_selector (PS_Record _ _) _\n\t\t\t\t\t\t\t=\tTrue\n\t\t\t\t\t\tsmaller_selector (PS_QualifiedRecord _ field_name1 _) (PS_QualifiedRecord _ field_name2 _)\n\t\t\t\t\t\t\t=\tfield_name1 < field_name2\n\t\t\t\t\t\tsmaller_selector (PS_QualifiedRecord _ field_name1 _) (PS_Record ident2 _)\n\t\t\t\t\t\t\t=\tfield_name1 < ident2.id_name\n\t\t\t\t\t\tsmaller_selector (PS_QualifiedRecord _ _ _) _\n\t\t\t\t\t\t\t=\tTrue\n\t\t\t\t\t\tsmaller_selector _ _\n\t\t\t\t\t\t\t=\tFalse\n\n\t\tgroupedUpdates\n\t\t\t\/\/ group nested updates by first field name\n\t\t\t=\tgroupBy equal_update sortedUpdates\n\t\t\twhere\n\t\t\t\tequal_update :: NestedUpdate NestedUpdate -> Bool\n\t\t\t\tequal_update a b\n\t\t\t\t\t=\tequal_selectors a.nu_selectors b.nu_selectors\n\t\t \t\t\twhere\n\t\t\t\t\t\tequal_selectors :: [ParsedSelection] [ParsedSelection] -> Bool\n\t\t\t\t\t\tequal_selectors [PS_Record ident1 _ ,_ : _] [PS_Record ident2 _ ,_: _]\n\t\t\t\t\t\t\t=\tident1.id_name == ident2.id_name\n\t\t\t\t\t\tequal_selectors [PS_QualifiedRecord _ field_name1 _ ,_ : _] [PS_QualifiedRecord _ field_name2 _ ,_: _]\n\t\t\t\t\t\t\t=\tfield_name1 == field_name2\n\t\t\t\t\t\tequal_selectors _ _\n\t\t\t\t\t\t\t=\tFalse\n\n\t\tgroupBy :: (a a -> Bool) [a] -> [[a]]\n\t\tgroupBy eq []\n\t\t = []\n\t\tgroupBy eq [h : t]\n\t\t = [[h : this] : groupBy eq other]\n\t\t where\n\t\t (this, other) = span (eq h) t\n\n\t\tis_record_update [{nu_selectors=[select : _]} : _]\n\t\t\t=\tis_record_select select\n\t\tis_record_update updates\n\t\t\t=\tFalse\n\n\t\tis_record_select (PS_Record _ _)\n\t\t\t=\tTrue\n\t\tis_record_select (PS_QualifiedRecord _ _ _)\n\t\t\t=\tTrue\n\t\tis_record_select _\n\t\t\t=\tFalse\n\n\t\ttransform_record_update :: OptionalRecordName ParsedExpr ![[NestedUpdate]] !Int ParseState -> (ParsedExpr, ParseState)\n\t\ttransform_record_update record_type expr groupedUpdates level pState\n\t\t\t=\t(updateExpr, pState2)\n\t\t\twhere\n\t\t\t\t\/* final_record_type on a cycle *\/\n\t\t\t\t(assignments, (optionalIdent, final_record_type,pState2))\n\t\t\t\t\t= mapSt (transform_update level) groupedUpdates (No, record_type,pState)\n\t\t\t\tupdateExpr\n\t\t\t\t\t= build_update final_record_type optionalIdent expr assignments\n\t\t\t\t\/\/ transform one group of nested updates with the same first field\n\t\t\t\t\/\/ for example: f.g1 = e1, f.g2 = e2 -> f = {id.f & g1 = e1, g2 = e2},\n\t\t\t\t\/\/ (id is ident to shared expression that's being updated)\n\n\t\t\t\ttransform_update :: !Int [NestedUpdate] (Optional Ident,OptionalRecordName,ParseState) -> (FieldAssignment, !(!Optional Ident,OptionalRecordName,ParseState))\n\t\t\t\ttransform_update _ [{nu_selectors=[PS_Record fieldIdent field_record_type], nu_update_expr}] (shareIdent,record_type,pState)\n\t\t\t\t\t# (record_type,pState) = check_field_and_record_types field_record_type record_type pState;\n\t\t\t\t\t= ({bind_dst = FieldName fieldIdent, bind_src = nu_update_expr},(shareIdent,record_type,pState))\n\t\t\t\ttransform_update _ [{nu_selectors=[PS_QualifiedRecord module_id field_name field_record_type], nu_update_expr}] (shareIdent,record_type,pState)\n\t\t\t\t\t# (record_type,pState) = check_field_and_record_types field_record_type record_type pState;\n\t\t\t\t\t= ({bind_dst = QualifiedFieldName module_id field_name, bind_src = nu_update_expr},(shareIdent,record_type,pState))\n\t\t\t\ttransform_update level updates=:[{nu_selectors=[PS_Record fieldIdent field_record_type : _]} : _] (optionalIdent,record_type,pState)\n\t\t\t\t\t# (record_type,pState) = check_field_and_record_types field_record_type record_type pState;\n\t\t\t\t\t (shareIdent, pState) = make_ident optionalIdent level pState\n\t\t\t\t\t select = PE_Selection ParsedNormalSelector (PE_Ident shareIdent) [PS_Record fieldIdent final_record_type]\n\t\t\t\t\t (update_expr, pState)\n\t\t\t\t\t \t=\ttransform_record_or_array_update NoRecordName select (map sub_update updates) (level+1) pState\n\t\t\t\t\t= ({bind_dst = FieldName fieldIdent, bind_src = update_expr}, (Yes shareIdent,record_type,pState))\n\t\t\t\ttransform_update level updates=:[{nu_selectors=[PS_QualifiedRecord module_id field_name field_record_type : _]} : _] (optionalIdent,record_type,pState)\n\t\t\t\t\t# (record_type,pState) = check_field_and_record_types field_record_type record_type pState;\n\t\t\t\t\t (shareIdent, pState) = make_ident optionalIdent level pState\n\t\t\t\t\t select = PE_Selection ParsedNormalSelector (PE_Ident shareIdent) [PS_QualifiedRecord module_id field_name final_record_type]\n\t\t\t\t\t (update_expr, pState)\n\t\t\t\t\t \t=\ttransform_record_or_array_update NoRecordName select (map sub_update updates) (level+1) pState\n\t\t\t\t\t= ({bind_dst = QualifiedFieldName module_id field_name, bind_src = update_expr}, (Yes shareIdent,record_type,pState))\n\t\t\t\ttransform_update _ _ (_, record_type,pState)\n\t\t\t\t\t# pState = parseError \"record or array\" No \"field assignments mixed with array assignments not\" pState\n\t\t\t\t\t=\t({bind_dst = FieldName errorIdent, bind_src = PE_Empty}, (No,record_type,pState))\n\n\t\t\t\tmake_ident :: (Optional Ident) !Int ParseState -> (Ident, ParseState)\n\t\t\t\tmake_ident (Yes ident) _ pState\n\t\t\t\t\t=\t(ident, pState)\n\t\t\t\tmake_ident No level pState\n\t\t\t\t\t=\tinternalIdent (\"s\" +++ toString level +++ \";\") pState\n\n\t\t\t\tsub_update :: NestedUpdate -> NestedUpdate\n\t\t\t\tsub_update update=:{nu_selectors}\n\t\t\t\t\t=\t{update & nu_selectors = tl nu_selectors}\n\n\t\t\t\tbuild_update :: !OptionalRecordName !(Optional Ident) !ParsedExpr ![FieldAssignment] -> ParsedExpr\n\t\t\t\tbuild_update record_type No expr assignments\n\t\t\t\t\t=\tPE_Record expr record_type assignments\n\t\t\t\tbuild_update record_type (Yes ident) expr assignments\n\t\t\t\t\t=\tPE_Let (LocalParsedDefs [buildNodeDef (PE_Ident ident) expr])\n\t\t\t\t\t\t\t\t(PE_Record (PE_Ident ident) record_type assignments)\n\t\t\t\t\n\t\t\t\tcheck_field_and_record_types :: OptionalRecordName OptionalRecordName ParseState -> (!OptionalRecordName,!ParseState);\n\t\t\t\tcheck_field_and_record_types NoRecordName record_type pState\n\t\t\t\t\t= (record_type,pState);\n\t\t\t\tcheck_field_and_record_types field_record_type=:(RecordNameIdent _) NoRecordName pState\n\t\t\t\t\t= (field_record_type,pState);\n\t\t\t\tcheck_field_and_record_types (RecordNameIdent field_record_type_name) record_type=:(RecordNameIdent record_type_name) pState\n\t\t\t\t\t| field_record_type_name==record_type_name\n\t\t\t\t\t\t= (record_type,pState);\n\t\t\t\t\t\t# error_message = \"record type in update: \"+++field_record_type_name.id_name+++\" where \"+++record_type_name.id_name+++\" was\"\n\t\t\t\t\t\t= (record_type,parseError \"record or array\" No error_message pState);\n\n\t\ttransform_array_update :: ParsedExpr [NestedUpdate] !Int ParseState -> (ParsedExpr, ParseState)\n\t\ttransform_array_update expr updates level pState\n\t\t\t\/\/ transform { & [i].<...> = e1, ... } to {{ & [i1].<...> = e1} & ...}\n\t\t\t=\tfoldSt (transform_update level) updates (expr, pState)\n\t\t\twhere\n\t\t\t\ttransform_update :: !Int NestedUpdate (ParsedExpr, ParseState) -> (ParsedExpr, ParseState)\n\t\t\t\ttransform_update level {nu_selectors, nu_update_expr} (expr1, pState)\n\t\t\t\t\t=\tbuild_update expr1 (split_selectors nu_selectors) nu_update_expr level pState\n\t\t\t\t\twhere\n\t\t\t\t\t\t\/\/ split selectors into final record selectors and initial selectors\n\t\t\t\t\t\t\/\/ (resulting selectors are reversed)\n\t\t\t\t\t\t\/\/\t\tfor example: [i1].[i2].f.[i3].g.h -> (h.g, [i3].f.[i2].[i1])\n\t\t\t\t\t\tsplit_selectors selectors\n\t\t\t\t\t\t\t=\tspan is_record_select (reverse selectors)\n\n\t\t\t\t\t\tbuild_update :: ParsedExpr ([ParsedSelection], [ParsedSelection]) ParsedExpr !Int ParseState -> (ParsedExpr, ParseState)\n\t\t\t\t\t\tbuild_update expr ([], initial_selectors) update_expr _ pState\n\t\t\t\t\t\t\t=\t(PE_Update expr (reverse initial_selectors) update_expr, pState)\n\t\t\t\t\t\t\/\/ transform { & <...>.[i].f.g. = e1} to\n\t\t\t\t\t\t\/\/ let\n\t\t\t\t\t\t\/\/\t\tindex_id = i\n\t\t\t\t\t\t\/\/\t\t(element_id, array_id) = !<...>.[index_id]\n\t\t\t\t\t\t\/\/\t in {array_id & [index_id] = {element_id & f.g = e1}}\n\t\t\t\t\t\tbuild_update expr (record_selectors, [PS_Array index : initial_selectors]) update_expr level pState\n\t\t\t\t\t\t\t# (index_id, pState)\n\t\t\t\t\t\t\t\t=\tinternalIdent (\"i\" +++ toString level +++ \";\") pState\n\t\t\t\t\t\t\t# (element_id, pState)\n\t\t\t\t\t\t\t\t=\tinternalIdent (\"e\" +++ toString level +++ \";\") pState\n\t\t\t\t\t\t\t# (array_id, pState)\n\t\t\t\t\t\t\t\t=\tinternalIdent (\"a\" +++ toString level +++ \";\") pState\n\t\t\t\t\t\t\t index_def\n\t\t\t\t\t\t\t \t=\tbuildNodeDef (PE_Ident index_id) index\n\t\t\t\t\t\t\t select_def\n\t\t\t\t\t\t\t \t=\tbuildNodeDef\n\t\t\t\t\t\t\t \t\t\t(PE_Tuple [PE_Ident element_id, PE_Ident array_id])\n\t\t\t\t\t\t\t \t\t\t(PE_Selection (ParsedUniqueSelector True) expr (reverse [PS_Array (PE_Ident index_id) : initial_selectors]))\n\t\t\t\t\t\t\t (updated_element, pState)\n\t\t\t\t\t\t\t\t= transform_record_update NoRecordName\n\t\t\t\t\t\t\t\t\t(PE_Ident element_id)\n\t\t\t\t\t\t\t\t\t[[{nu_selectors=(reverse record_selectors), nu_update_expr=update_expr}]] (level+1) pState\n\t\t\t\t\t\t\t=\t(PE_Let\n\t\t\t\t\t\t\t\t\t(LocalParsedDefs [index_def, select_def])\n\t\t\t\t\t\t\t\t\t(PE_Update (PE_Ident array_id) (reverse [PS_Array (PE_Ident index_id) : initial_selectors]) updated_element), pState)\n\nwant_field_assignments is_pattern token=:(IdentToken field_name) pState\n\t| isLowerCaseName field_name\n\t\t# (field_id, pState) = stringToIdent field_name IC_Selector pState\n\t\t= want_more_field_assignments (FieldName field_id) is_pattern pState\nwant_field_assignments is_pattern token=:(QualifiedIdentToken module_name field_name) pState\n\t| isLowerCaseName field_name\n\t\t# (module_id, pState) = stringToIdent module_name (IC_Module NoQualifiedIdents) pState\n\t\t= want_more_field_assignments (QualifiedFieldName module_id field_name) is_pattern pState\nwant_field_assignments is_pattern token pState\n\t= ([], parseError \"record or array field assignments\" (Yes token) \"field name\" pState)\n\nwant_more_field_assignments field_name_or_qualified_field_name is_pattern pState\n\t# (field_expr, pState) = want_field_expression is_pattern pState\n\t field = { bind_src = field_expr, bind_dst = field_name_or_qualified_field_name}\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == CommaToken\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t (fields, pState) = want_field_assignments is_pattern token pState \n\t\t= ([ field : fields ], pState)\n\t\t= ([ field ], tokenBack pState)\n\ntry_field_assignment (IdentToken field_name) pState\n\t| isLowerCaseName field_name\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == EqualToken\n\t\t\t# (field_expr, pState) = wantExpression pState\n\t\t\t (field_id, pState) = stringToIdent field_name IC_Selector pState\n\t\t\t= (True, { bind_src = field_expr, bind_dst = FieldName field_id}, pState) \n\t\t\t= (False, abort \"no field\", tokenBack pState)\n\t\t= (False, abort \"no field\", pState)\ntry_field_assignment (QualifiedIdentToken module_name field_name) pState\n\t| isLowerCaseName field_name\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == EqualToken\n\t\t\t# (field_expr, pState) = wantExpression pState\n\t\t\t (module_id, pState) = stringToIdent module_name (IC_Module NoQualifiedIdents) pState\n\t\t\t= (True, { bind_src = field_expr, bind_dst = QualifiedFieldName module_id field_name}, pState) \n\t\t\t= (False, abort \"no field\", tokenBack pState)\n\t\t= (False, abort \"no field\", pState)\ntry_field_assignment _ pState\n\t= (False, abort \"no field\", pState)\n\nwant_field_expression is_pattern pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == EqualToken\n\t\t= wantExpressionOrPattern is_pattern pState\n\t\t= (PE_Empty, tokenBack pState)\n\nwant_record :: !OptionalRecordName !ParseState -> (!ParsedExpr,!ParseState)\t\t\nwant_record type pState\n\t# (token1, pState) = nextToken FunctionContext pState\n\t (token2, pState) = nextToken FunctionContext pState\n\t| isDefinesFieldToken token2\n\t\t# (fields, pState) = want_field_assignments cIsNotAPattern token1 (tokenBack pState)\n\t\t= (PE_Record PE_Empty type fields, wantToken FunctionContext \"record\" CurlyCloseToken pState)\n\t\t= want_record_update type token1 (tokenBack pState)\nwhere\n\twant_record_update :: !OptionalRecordName !Token !ParseState -> (!ParsedExpr, !ParseState)\n\twant_record_update type token pState\n\t\t# (expr, pState)\t= wantExpressionT token pState\n\t\t pState\t\t\t= wantToken FunctionContext \"record update\" AndToken pState\n\t\t (token, pState)\t= nextToken FunctionContext pState\n\t\t= want_update type expr token pState\n\nwantRecordPatternWithoutDefinitions :: !ParseState -> (ParsedExpr, !ParseState)\nwantRecordPatternWithoutDefinitions pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == CurlyCloseToken\n\t\t= (PE_Empty, parseError \"record pattern\" No \"Array denotation not\" pState)\n\t\t= want_record_pattern_without_definitions token pState\nwhere\n\twant_record_pattern_without_definitions (IdentToken name) pState\n\t\t| isUpperCaseName name\n\t\t\t# pState = wantToken FunctionContext \"record pattern\" BarToken pState\n\t\t\t (type_id, pState) = stringToIdent name IC_Type pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (fields, pState) = want_field_assignments_without_definitions token pState\n\t\t\t= (PE_Record PE_Empty (RecordNameIdent type_id) fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState)\n\twant_record_pattern_without_definitions (QualifiedIdentToken module_name record_name) pState\n\t\t| isUpperCaseName record_name\n\t\t\t# pState = wantToken FunctionContext \"record pattern\" BarToken pState\n\t\t\t (module_id, pState) = stringToQualifiedModuleIdent module_name record_name IC_Type pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (fields, pState) = want_field_assignments_without_definitions token pState\n\t\t\t= (PE_Record PE_Empty (RecordNameQualifiedIdent module_id record_name) fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState) \n\twant_record_pattern_without_definitions token pState\n\t\t# (fields, pState) = want_field_assignments_without_definitions token pState\n\t\t= (PE_Record PE_Empty NoRecordName fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState) \n\n\twant_field_assignments_without_definitions token=:(IdentToken field_name) pState\n\t\t| isLowerCaseName field_name\n\t\t\t# (field_id, pState) = stringToIdent field_name IC_Selector pState\n\t\t\t= want_more_field_assignments_without_definitions (FieldName field_id) pState\n\twant_field_assignments_without_definitions token=:(QualifiedIdentToken module_name field_name) pState\n\t\t| isLowerCaseName field_name\n\t\t\t# (module_id, pState) = stringToIdent module_name (IC_Module NoQualifiedIdents) pState\n\t\t\t= want_more_field_assignments_without_definitions (QualifiedFieldName module_id field_name) pState\n\twant_field_assignments_without_definitions token pState\n\t\t= ([], parseError \"record field assignments\" (Yes token) \"field name\" pState)\n\n\twant_more_field_assignments_without_definitions field_name_or_qualified_field_name pState\n\t\t# pState = wantToken FunctionContext \"record pattern\" EqualToken pState\n\t\t# (field_expr, pState) = wantPattern pState\n\t\t field = {bind_src = field_expr, bind_dst = field_name_or_qualified_field_name}\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t (fields, pState) = want_field_assignments_without_definitions token pState \n\t\t\t= ([field : fields], pState)\n\t\t\t= ([field ], tokenBack pState)\n\nwant_update :: !OptionalRecordName !ParsedExpr !Token !ParseState -> (!ParsedExpr, !ParseState)\nwant_update type expr token pState\n\t# (expr, pState) = want_update_without_curly_close type expr token pState\n\t pState = wantToken FunctionContext \"update\" CurlyCloseToken pState\n\t= (expr, pState)\n\nwant_update_without_curly_close :: !OptionalRecordName !ParsedExpr !Token !ParseState -> (!ParsedExpr, !ParseState)\nwant_update_without_curly_close type expr token pState\n\t# (position, pState) = getPosition pState\n\t (updates, pState)\t= want_updates type token pState\n\t (qualifiers, pState) = try_qualifiers pState\n\t (updatable_expr, pState) = test_qualifiers expr (toLineAndColumn position) qualifiers pState\n\t (updated_expr, pState) = transform_record_or_array_update type updatable_expr updates 0 pState\n\t= (add_qualifiers qualifiers expr updated_expr updatable_expr, pState)\n\twhere\n\t\ttry_qualifiers :: !ParseState -> (![Qualifier], !ParseState)\n\t\ttry_qualifiers pState\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == DoubleBackSlashToken\n\t\t\t\t= wantQualifiers pState\n\t\t\t\t= ([], tokenBack pState)\n\n\t\ttest_qualifiers :: !ParsedExpr !LineAndColumn [Qualifier] !ParseState -> (!ParsedExpr, !ParseState)\n\t\ttest_qualifiers updateExpr _ [] pState\n\t\t\t=\t(updateExpr, pState)\n\t\ttest_qualifiers updateExpr {lc_line, lc_column} qualifiers pState\n\t\t\t# (ident, pState)\n\t\t\t\t=\tstringToIdent (\"a;\" +++ toString lc_line +++ \";\" +++ toString lc_column) IC_Expression pState\n\t\t\t=\t(PE_Ident ident, pState)\n\n\t\tadd_qualifiers :: ![Qualifier] !ParsedExpr !ParsedExpr !ParsedExpr -> ParsedExpr\n\t\tadd_qualifiers [] _ update_expr _\n\t\t\t=\tupdate_expr\n\t\tadd_qualifiers qualifiers expr update_expr ident_expr\n\t\t\t=\tPE_UpdateComprehension expr update_expr ident_expr qualifiers\n\nwant_record_or_array_update token expr pState\n\t= want_update NoRecordName expr token pState\n\nwant_array_assignments pState\n\t# (assign, pState) = want_array_assignment pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == CommaToken\n\t\t# pState = wantToken FunctionContext \"array assignments\" SquareOpenToken pState\n\t\t (assigns, pState) = want_array_assignments pState \n\t\t= ([ assign : assigns ], pState)\n\t\t= ([ assign ], tokenBack pState)\nwhere\n\twant_array_assignment pState\n\t\t# (index_exprs, pState) = want_index_exprs pState\n\t\t pState = wantToken FunctionContext \"array assignment\" EqualToken pState\n\t\t (pattern_exp, pState) = wantPattern pState\n\t\t= ({bind_dst = index_exprs, bind_src = pattern_exp}, pState)\n\n\twant_index_exprs pState\n\t\t# (index_expr, pState) = wantExpression pState\n\t\t (token, pState) = nextToken GeneralContext pState\n\t\t| token==CommaToken\n\t\t\t# (index_exprs, pState) = want_index_exprs pState\n\t\t\t= ([index_expr:index_exprs], pState)\n\t\t| token==SquareCloseToken\n\t\t\t= ([index_expr], pState)\n\t\t= ([], parseError \"\" (Yes token) \"] or ,\" pState)\n\/**\n\tEnd of definitions\n**\/\n\nskipToEndOfDefinition :: !ParseState -> (!Token, !ParseState)\nskipToEndOfDefinition pState\n\t# (token, pState)\t\t= nextToken FunctionContext pState\n\t= case token of\n\t\tNewDefinitionToken\t-> (token, pState)\n\t\tEndGroupToken\t\t-> (token, pState)\n\t\tEndOfFileToken\t\t-> (token, pState)\n\/\/\t\tSemicolonToken\t\t-> (token, pState) \/\/ might be useful in non layout mode.\n\t\t_\t\t\t\t\t-> skipToEndOfDefinition pState \/\/ -->> (token,\"skipped\")\n\nwantEndCodeRhs :: !ParseState -> ParseState\nwantEndCodeRhs pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t| ss_useLayout\n\t\t= wantEndOfDefinition \"code rhs\" pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == SemicolonToken\n\t\t= pState\n\t\t= tokenBack pState\n\nwantEndOfDefinition :: String !ParseState -> ParseState\nwantEndOfDefinition msg pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t#\t(token, pState) = skipToEndOfDefinition {pState & ps_flags = pState.ps_flags bitand (bitnot PS_SkippingMask)}\n\t\t= want_end_of_definition token msg pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= want_end_of_definition token msg pState\nwhere\n\twant_end_of_definition :: !Token String !ParseState -> ParseState\n\twant_end_of_definition token msg pState\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t| ss_useLayout\n\t\t\t= case token of\n\t\t\t\tNewDefinitionToken\t->\tpState \n\t\t\t\tEndOfFileToken\t\t->\ttokenBack pState\n\t\t\t\tEndGroupToken \t\t->\ttokenBack pState\n\t\t\t\tInToken\t\t \t\t->\ttokenBack pState\n\t\t\t\tWhereToken\t\t\t->\ttokenBack pState\n\t\t\t\tBarToken\t\t\t->\ttokenBack pState\n\t\t\t\tEqualToken\t\t\t->\ttokenBack pState\n\t\t\t\tArrowToken\t\t\t->\ttokenBack pState\n\t\t\t\tSeqLetToken _\t\t->\ttokenBack pState\n\t\t\t\tSemicolonToken\t\t#\t(token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t\t\t->\tcase token of\n\t\t\t\t\t\t\t\t\t\t\tNewDefinitionToken\t->\tpState\n\t\t\t\t\t\t\t\t\t\t\t_\t\t\t\t\t->\ttokenBack pState\n\t\t\t\ttoken\t\t\t\t->\twantEndOfDefinition \"\" (parseError msg (Yes token) \"end of definition\" pState)\n\t\t\/\/ otherwise \/\/ ~ ss_useLayout\n\t\t\t= case token of\n\t\t\t\tCurlyCloseToken\t\t->\ttokenBack pState\n\t\t\t\tSemicolonToken\t\t->\tpState\n\t \t\t\tEndOfFileToken\t\t->\ttokenBack pState\n\t\t\t\ttoken\t\t\t\t->\twantEndOfDefinition \"\" (parseError msg (Yes token) \"end of definition\" pState)\n\nwantEndRootExpression :: !ParseState -> ParseState\nwantEndRootExpression pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t=\twantEndOfDefinition \"root expression\" pState\n\t\t#\t(token, pState)\t\t\t= nextToken FunctionContext pState\n\t\t\t(ss_useLayout, pState)\t= accScanState UseLayout pState\n\t\t| ss_useLayout\n\t\t\t= case token of\n\t\t\t\tNewDefinitionToken\t->\tpState\n\t\t\t\tEndOfFileToken\t\t->\ttokenBack pState\n\t\t\t\tEndGroupToken \t\t->\ttokenBack pState\n\t\t\t\tEqualToken \t\t\t->\ttokenBack pState\n\t\t\t\tArrowToken \t\t\t->\ttokenBack pState\n\t\t\t\tWhereToken\t\t\t->\ttokenBack pState\n\t\t\t\tWithToken\t\t\t->\ttokenBack pState\n\t\t\t\tBarToken\t\t\t->\ttokenBack pState\n\t\t\t\tInToken\t\t \t\t->\ttokenBack pState\n\t\t\t\tCloseToken\t \t\t->\ttokenBack pState\n\t\t\t\tSquareCloseToken\t->\ttokenBack pState\n\t\t\t\tCommaToken\t \t\t->\ttokenBack pState\n\t\t\t\tColonToken\t \t\t->\ttokenBack pState\n\t\t\t\t(SeqLetToken _)\t\t->\ttokenBack pState\n\t\t\t\tSemicolonToken\t\t#\t(token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t\t\t->\tcase token of\n\t\t\t\t\t\t\t\t\t\t\tNewDefinitionToken\t->\tpState\n\t\t\t\t\t\t\t\t\t\t\t_\t\t\t\t\t->\ttokenBack pState\n\t\t\t\tCurlyCloseToken\t\t->\ttokenBack pState \n\t\t\t\ttoken\t\t\t\t->\twantEndOfDefinition \"root expression\" (parseError \"root expression\" (Yes token) \"end of root expression\" pState)\n\t\t\/\/ otherwise \/\/ ~ ss_useLayout\n\t\t\t= case token of\n\t\t\t\tSemicolonToken\t\t->\tpState\n\t\t\t\tCurlyCloseToken\t\t->\ttokenBack pState\n\t\t\t\tEqualToken \t\t\t->\ttokenBack pState\n\t\t\t\tArrowToken \t\t\t->\ttokenBack pState\n\t\t\t\t(SeqLetToken _)\t\t->\ttokenBack pState\n\t\t\t\tWhereToken\t\t\t->\ttokenBack pState\n\t\t\t\tWithToken\t\t\t->\ttokenBack pState\n\t\t\t\tBarToken\t\t\t->\ttokenBack pState\n\t \t\t\tEndOfFileToken\t\t->\ttokenBack pState\n\t\t\t\ttoken\t\t\t\t->\twantEndOfDefinition \"root expression\" (parseError \"root expression\" (Yes token) \"end of root expression\" pState)\n\nwantEndGroup :: String !ParseState -> ParseState\nwantEndGroup msg pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == EndOfFileToken\n\t\t= tokenBack pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t| ss_useLayout\n\t\t= case token of\n\t\t\tEndGroupToken\t->\tpState\n\t\t\tInToken\t\t\t->\ttokenBack pState\n\t\t\t_\t\t\t\t->\tparseError msg (Yes token) \"end of group with layout\" pState\n\t\/\/ ~ ss_useLayout\n\t| token == CurlyCloseToken\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == SemicolonToken\n\t\t\t= pState\n\t\t\t= tokenBack pState\n\t\t= parseError msg (Yes token) \"end of group without layout, },\" pState\n\nwantEndModule :: !ParseState -> ParseState\nwantEndModule pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == EndOfFileToken\n\t\t= tokenBack pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t| ss_useLayout && token == EndGroupToken\n\t\t= pState\n\t\t= parseError \"Definition\" (Yes token) \"Unexpected token in input: definition\" pState\n\nwantEndNestedGuard :: !Bool !Int !ParseState -> ParseState\nwantEndNestedGuard defaultFound offside pState\n\t| ~ defaultFound\n\t\t= parseError \"nested guards\" No \"sorry, but for the time being there is a default alternative for nested guards\" pState\n\t# (token, pState)\t\t\t= nextToken FunctionContext pState\n\t| token == EndOfFileToken\n\t\t= tokenBack pState\n\t# (ss_useLayout, pState)\t= accScanState UseLayout pState\n\t| ss_useLayout\n\t\t# ({fp_col}, pState)\t= getPosition pState\n\t\t| fp_col < offside || (end_Nested_Guard token && fp_col == offside)\n\t\t\t= tokenBack pState\n\t\t\/\/ otherwise\n\t\t\t= parseError \"nested guards\" (Yes token) \"=, ->, | or # at offside position, or end of function definition\" pState\n\t\/\/ ~ ss_useLayout\n\t| token == SemicolonToken\n\t\t= pState\n\t| defaultFound\n\t\t= tokenBack pState\n\t\/\/ otherwise\n\t\t= parseError \"nested guards\" (Yes token) \"End of nested guards, ;,\" pState\nwhere\n\tend_Nested_Guard EqualToken\t\t\t= True\n\tend_Nested_Guard BarToken\t\t\t= True\n\tend_Nested_Guard ArrowToken\t\t\t= True\n\tend_Nested_Guard (SeqLetToken _)\t= True\n\tend_Nested_Guard _\t\t\t\t\t= False\n\nwantEndLocals :: !ParseState -> ParseState\nwantEndLocals pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == EndOfFileToken && ss_useLayout\n\t\t= tokenBack pState\n\t| ss_useLayout\n\t\t= case token of\n\t\t\tEndGroupToken\t->\tpState\n\t\t\tInToken\t\t\t->\ttokenBack (appScanState dropOffsidePosition pState) \/\/ PK\n\t\/\/\t\tInToken\t\t\t->\ttokenBack pState\t\/\/ For let expressions with cases\n\t\t\t_\t\t\t\t->\tparseError \"local definitions\" (Yes token) \"end of locals with layout\" pState\n\t\/\/ ~ ss_useLayout\n\t| token == CurlyCloseToken\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == SemicolonToken\n\t\t\t= pState\n\t\t\t= tokenBack pState\n\t\/\/ otherwise \/\/ token <> CurlyCloseToken\n\t\t= parseError \"local definitions\" (Yes token) \"end of locals without layout, },\" pState\n\nwantEndCase :: !ParseState -> ParseState\nwantEndCase pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == EndOfFileToken\n\t\t= tokenBack pState\n\t| ss_useLayout\n\t\t= case token of\n\t\t\tEndGroupToken\t\t->\tpState\n\t\t\tCloseToken\t\t\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tSquareCloseToken\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tSemicolonToken\t\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tCommaToken\t\t\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tColonToken\t\t\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tInToken\t\t\t\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tCurlyCloseToken\t\t->\ttokenBack (appScanState dropOffsidePosition pState) \/\/ PK\n\t\t\t_\t\t\t\t\t->\tparseError \"case expression\" (Yes token) \"end of case with layout\" pState\n\t\/\/ ~ ss_useLayout\n\t| token == CurlyCloseToken\n\t\t= pState\n\t\/\/ otherwise \/\/ token <> CurlyCloseToken\n\t\t= parseError \"case expression\" (Yes token) \"end of group without layout, },\" pState\n\nwantBeginGroup :: String !ParseState -> ParseState\nwantBeginGroup msg pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t| ss_useLayout\n\t\t= pState\n\t\/\/ otherwise \/\/ ~ ss_uselayout\n\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tCurlyOpenToken\n\t\t\t\t->\tpState\n\t\t\t_\t->\tparseError msg (Yes token) \"begin group without layout, {,\" pState\n\n\/\/ AA..\nwantKind :: !ParseState -> (!TypeKind, !ParseState)\nwantKind pState\n\t| pState.ps_flags bitand PS_SupportGenericsMask==0\n\t\t= (KindConst, parseErrorSimple \"kind\" \"to enable generics use -generics command line flag\" pState)\n\t# (token, pState) = nextToken TypeContext pState\n\t# (kind, pState) = want_simple_kind token pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= want_kind kind token pState\n\twhere\n\t\twant_simple_kind AsteriskToken pState\t\t= (KindConst, pState)\n\t\twant_simple_kind (IntToken str) pState\n\t\t\t# n = toInt str\n\t\t\t| n == 0\t= (KindConst, pState)\n\t\t\t| n > 0 \t= (KindArrow (repeatn n KindConst), pState)\n\t\t\t| otherwise = (KindConst, parseError \"invalid kind\" No \"positive integer expected\" pState)\n\t\twant_simple_kind OpenToken pState \t\t\t= wantKind pState\n\t\twant_simple_kind GenericOpenToken pState \t= wantKind pState\n\t\twant_simple_kind token pState \n\t\t\t= (KindConst, parseError \"invalid kind\" (Yes token) \"* or (\" pState)\n\n\t\twant_kind kind ArrowToken pState\n\t\t\t# (rhs, pState) = wantKind pState\n\t\t\t= \tcase rhs of\n\t\t\t\t(KindArrow ks) \t-> (KindArrow [kind : ks], pState)\n\t\t\t\tKindConst \t\t-> (KindArrow [kind], pState) \n\t\t\t\t\/\/_\t\t\t\t-> (KindArrow [kind, rhs], pState)\n\t\twant_kind kind CloseToken pState \t\t\t\t= (kind, pState)\n\t\twant_kind kind GenericCloseToken pState \t\t= (kind, pState)\n\t\twant_kind kind token pState\t\n\t\t\t= (kind, parseError \"invalid kind\" (Yes token) \")\" pState)\n\/\/ ..AA \n\n\/*\n\tFunctions on the parse pState\n*\/\n\/*\ninstance insertToken ParseState\nwhere\n\tinsertToken t c pState = appScanState (insertToken t c) pState\n\ninstance currentToken ParseState\nwhere\n\tcurrentToken pState = accScanState currentToken pState\n\t\ninstance replaceToken ParseState\nwhere\n\treplaceToken t pState = appScanState (replaceToken t) pState\n*\/\ninstance tokenBack ParseState\nwhere\n\ttokenBack pState\n\t\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t\t= pState\n\t\t\t= appScanState tokenBack pState\n\ninstance nextToken ParseState\nwhere\n\tnextToken :: !ScanContext !ParseState -> (!Token, !ParseState)\n\tnextToken scanContext pState\n\t\t| pState.ps_flags bitand PS_SkippingMask<>0 \/\/ in error recovery from parse error\n\t\t\t= (ErrorToken \"Skipping\", pState)\n\t\t\t= accScanState (nextToken scanContext) pState\n\ninstance getPosition ParseState\nwhere\n\tgetPosition pState = accScanState getPosition pState\n\nwarnIfStrictAnnot NoAnnot pState = pState\nwarnIfStrictAnnot (StrictAnnotWithPosition position) pState = parseWarningWithPosition \"\" \"! ignored\" position pState\n\nparseWarningWithPosition :: !{# Char} !{# Char} !FilePosition !ParseState -> ParseState\nparseWarningWithPosition act msg position pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t= pState\n\t| otherwise \/\/ not pState.ps_skipping\n\t\t# (filename,pState=:{ps_error={pea_file,pea_ok}})\t= getFilename pState\n\t\t pea_file \t= \tpea_file\n\t\t \t\t\t\t<<< \"Parse warning [\"\n\t\t \t\t\t\t<<< filename <<< \",\"\n\t\t \t\t\t\t<<< position\n\t\t \t\t\t\t<<< (if (size act > 0) (\",\" + act) \"\") <<< \"]: \"\n\t\t \t\t\t\t<<< msg\n\t\t \t\t\t\t<<< \"\\n\"\n\t\t=\t{ pState\n\t\t\t& ps_error\t\t= { pea_file = pea_file, pea_ok = pea_ok }\n\t\t\t}\n\nparseWarning :: !{# Char} !{# Char} !ParseState -> ParseState\nparseWarning act msg pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t= pState\n\t| otherwise \/\/ not pState.ps_skipping\n\t\t# (pos,pState) \t= getPosition pState\n\t\t (filename,pState=:{ps_error={pea_file,pea_ok}})\t= getFilename pState\n\t\t pea_file \t= \tpea_file\n\t\t \t\t\t\t<<< \"Parse warning [\"\n\t\t \t\t\t\t<<< filename <<< \",\"\n\t\t \t\t\t\t<<< pos \n\t\t \t\t\t\t<<< (if (size act > 0) (\",\" + act) \"\") <<< \"]: \"\n\t\t \t\t\t\t<<< msg\n\t\t \t\t\t\t<<< \"\\n\"\n\t\t=\t{ pState\n\t\t\t& ps_error\t\t= { pea_file = pea_file, pea_ok = pea_ok }\n\t\t\t}\n\nparseError :: !{# Char} !(Optional Token) !{# Char} !ParseState -> ParseState\nparseError act opt_token msg pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t= pState\n\t| otherwise \/\/ not pState.ps_skipping\n\t\t# (pos,pState) \t= getPosition pState\n\t\t (filename,pState=:{ps_error={pea_file}})\t= getFilename pState\n\t\t pea_file \t= \tpea_file\n\t\t \t\t\t\t<<< \"Parse error [\"\n\t\t \t\t\t\t<<< filename <<< \",\"\n\t\t \t\t\t\t<<< pos \n\t\t \t\t\t\t<<< (if (size act > 0) (\",\" + act) \"\") <<< \"]: \"\n\t\t \t\t\t\t<<< msg\n\t\t pea_file\t= case opt_token of\n\t\t \t\t\t\tYes token\t-> pea_file <<< \" expected instead of \" <<< token <<< \"\\n\"\n\t\t \t\t\t\tNo\t\t\t-> pea_file <<< \" expected\\n\"\n\t\t pState \t=\t{ pState\n\t\t\t\t\t\t& ps_flags = pState.ps_flags bitor PS_SkippingMask\n\t\t\t\t\t\t, ps_error = { pea_file = pea_file, pea_ok = False }\n\t\t\t\t\t\t}\n\t\t= case opt_token of\n\t\t\tYes _\t-> tokenBack pState\n\t\t\tNo\t\t-> pState\n\nparseErrorSimple :: !{# Char} !{# Char} !ParseState -> ParseState\nparseErrorSimple act msg pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t= pState\n\t| otherwise \/\/ not pState.ps_skipping\n\t\t# (pos,pState) \t= getPosition pState\n\t\t (filename,pState=:{ps_error={pea_file}})\t= getFilename pState\n\t\t pea_file \t= \tpea_file\n\t\t \t\t\t\t<<< \"Parse error [\"\n\t\t \t\t\t\t<<< filename <<< \",\"\n\t\t \t\t\t\t<<< pos \n\t\t \t\t\t\t<<< (if (size act > 0) (\",\" + act) \"\") <<< \"]: \"\n\t\t \t\t\t\t<<< msg\n\t\t \t\t\t\t<<< '\\n'\n\t\t= { pState\t& ps_flags = pState.ps_flags bitor PS_SkippingMask\n\t\t\t\t\t, ps_error = { pea_file = pea_file, pea_ok = False }\n\t\t }\n\ngetFileAndLineNr :: !ParseState -> (!String, !Int, !ParseState)\ngetFileAndLineNr pState =: {ps_scanState}\n\t# (filename,scanState)\t= getFilename ps_scanState\n\t ({fp_line},scanState)\t= getPosition scanState\n\t= (filename, fp_line, {pState & ps_scanState = scanState} )\n\n\/*\n\tSimple parse functions\n*\/\n\nwantToken :: !ScanContext !{#Char} !Token !ParseState -> ParseState\nwantToken scanContext act dem_token pState\n\t# (token, pState) = nextToken scanContext pState\n\t| dem_token == token\n\t\t= pState\n\t\t= parseError act (Yes token) (toString dem_token) pState\n\ninstance want Priority\nwhere\n\twant pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tPriorityToken prio\n\t\t\t\t-> (prio, pState)\n\t\t\t_\n\t\t\t\t-> (NoPrio, parseError \"Priority\" (Yes token) \"with\" pState)\n\ninstance want {# Char}\nwhere\n\twant pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t= case token of\n\t\t\tIdentToken name -> (name, pState)\n\t\t\t_\t\t\t\t-> (\"\", parseError \"String\" (Yes token) \"identifier\" pState)\n\nwantModuleName :: !*ParseState -> (!{# Char}, !*ParseState)\nwantModuleName pState\n\t# (token, pState) = nextToken ModuleNameContext pState\n\t= case token of\n\t\tIdentToken name -> (name, pState)\n\t\tUnderscoreIdentToken name -> (name, pState)\n\t\t_\t\t\t\t-> (\"\", parseError \"String\" (Yes token) \"module name\" pState)\n\nwantOptionalQualifiedAndModuleName :: !*ParseState -> (!ImportQualified,!{#Char},!*ParseState)\nwantOptionalQualifiedAndModuleName pState\n\t# (token, pState) = nextToken ModuleNameContext pState\n\t= case token of\n\t\tIdentToken name1=:\"qualified\"\n\t\t\t# (token, pState) = nextToken ModuleNameContext pState\n\t\t\t-> case token of\n\t\t\t\tIdentToken name\n\t\t\t\t\t-> (Qualified, name, pState)\n\t\t\t\tUnderscoreIdentToken name\n\t\t\t\t\t-> (Qualified, name, pState)\n\t\t\t\tQualifiedIdentToken module_dname module_fname\n\t\t\t\t\t-> (Qualified, module_dname+++\".\"+++module_fname, pState)\n\t\t\t\t_\n\t\t\t\t\t-> (NotQualified, name1, tokenBack pState)\n\t\tIdentToken name\t\n\t\t\t-> (NotQualified, name, pState)\n\t\tUnderscoreIdentToken name\n\t\t\t-> (NotQualified, name, pState)\n\t\tQualifiedIdentToken module_dname module_fname\n\t\t\t-> (NotQualified, module_dname+++\".\"+++module_fname, pState)\n\t\t_\n\t\t\t-> (NotQualified, \"\", parseError \"String\" (Yes token) \"module name\" pState)\n\ntryTypeVar :: !ParseState -> (!Bool, TypeVar, !ParseState)\ntryTypeVar pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= tryTypeVarT token pState\n\ntryTypeVarT :: !Token !ParseState -> (!Bool, TypeVar, !ParseState)\ntryTypeVarT (IdentToken name) pState\n\t| isLowerCaseName name\n\t\t# (id, pState) = stringToIdent name IC_Type pState\n\t\t= (True, MakeTypeVar id, pState)\n\t\t= (False, abort \"no UC ident\", tokenBack pState)\ntryTypeVarT token pState\n\t\t= (False, abort \"no type variable\", tokenBack pState)\n\nwantUpperCaseName :: !String !ParseState -> (!String, !ParseState)\nwantUpperCaseName string pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tIdentToken name \n\t\t\t| isUpperCaseName name\n\t\t\t\t-> (name, pState)\n\t\t_\t-> (\"dummy uppercase name\", parseError string (Yes token) \"upper case ident\" pState)\n\/*\nwantNonUpperCaseName :: !String !ParseState -> (!String, !ParseState)\nwantNonUpperCaseName string pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tIdentToken name \n\t\t\t| ~ (isUpperCaseName name)\n\t\t\t\t-> (name, pState)\n\t\t_\t-> (\"dummy non uppercase name\", parseError string (Yes token) \"non upper case ident\" pState)\n*\/\nwantLowerCaseName :: !String !ParseState -> (!String, !ParseState)\nwantLowerCaseName string pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tIdentToken name \n\t\t\t| isLowerCaseName name\n\t\t\t\t-> (name, pState)\n\t\t_\n\t\t\t-> (\"dummy lowercase name\", parseError string (Yes token) \"lower case ident\" pState)\n\nwantConstructorName :: !String !ParseState -> (!String, !ParseState)\nwantConstructorName string pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tIdentToken name \n\t\t\t| isUpperCaseName name || isFunnyIdName name\n\t\t\t\t-> (name, pState)\n\t\t_\n\t\t\t-> (\"\", parseError string (Yes token) \"upper case ident\" pState)\n\nisDefinesFieldToken :: ! Token -> Bool\nisDefinesFieldToken EqualToken = True\nisDefinesFieldToken CurlyCloseToken = True\nisDefinesFieldToken CommaToken = True\nisDefinesFieldToken token = False\n\n \/\/---------------\/\/\n \/\/--- Tracing ---\/\/\n\/\/---------------\/\/\n\n(-->>) val _ :== val\n\/\/(-->>) val message :== val ---> (\"Parser\",message)\n","old_contents":"implementation module parse\n\nimport StdEnv\nimport scanner, syntax, hashtable, utilities, predef, containers, genericsupport\n\nParseOnly :== False\n\ntoLineAndColumn {fp_line, fp_col}\n\t=\t{lc_line = fp_line, lc_column = fp_col}\n\n\/*\n\nParser for Clean 2.0\n\nConventions:\n\n- Parsing funtions with a name of the form try.. can fail without generating an error.\n The parser will try an other alternative.\n- Parsing functions with a name of the form want.. should succeed. If these functions\n fail an error message is generated.\n- Functions with names containing the character '_' are local functions.\n- All functions should consume the tokens taken form the state or given as argument,\n or put these tokens back themselves.\n*\/\n\n::\t*ParseErrorAdmin = \n\t{\tpea_file\t:: !*File\n\t,\tpea_ok\t\t:: !Bool\n\t}\n\n:: *ParseState =\n\t{\tps_scanState\t\t:: !ScanState\n\t,\tps_error\t\t\t:: !*ParseErrorAdmin\n\t,\tps_flags\t\t\t:: !Int\n\t,\tps_hash_table\t\t:: !*HashTable\n\t}\n\nPS_SkippingMask :== 1\nPS_SupportGenericsMask :==2\nPS_DynamicTypeUsedMask :== 4\n\n\/*\nappScanState :: (ScanState -> ScanState) !ParseState -> ParseState\nappScanState f pState=:{ps_scanState}\n\t#\tps_scanState = f ps_scanState\n\t=\t{\tpState & ps_scanState = ps_scanState }\n*\/\nappScanState f pState:==appScanState pState\n\twhere\n\tappScanState pState=:{ps_scanState}\n\t\t#\tps_scanState = f ps_scanState\n\t\t=\t{\tpState & ps_scanState = ps_scanState }\n\n\/*\naccScanState :: (ScanState -> (.t,ScanState)) !ParseState -> (.t,ParseState)\naccScanState f pState=:{ps_scanState}\n\t#\t( x, ps_scanState) = f ps_scanState\n\t=\t( x, {pState & ps_scanState = ps_scanState })\n*\/\naccScanState f pState:== accScanState pState\n\twhere\n\t\taccScanState pState=:{ps_scanState}\n\t\t\t#\t( x, ps_scanState) = f ps_scanState\n\t\t\t=\t( x, {pState & ps_scanState = ps_scanState })\n\ninstance getFilename ParseState\nwhere\n\tgetFilename pState = accScanState getFilename pState\n\nmakeStringType\n\t#! string_ident = predefined_idents.[PD_StringType]\n\t=: TA (MakeNewTypeSymbIdent string_ident 0) []\n\nHeadLazy:==0\nHeadStrict:==1\nHeadUnboxed:==2\nHeadOverloaded:==3;\nHeadUnboxedAndTailStrict:==4;\n\nmakeListTypeSymbol :: Int Int -> TypeSymbIdent\nmakeListTypeSymbol head_strictness arity\n\t# pre_def_list_index=if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_ListType\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictListType\n\t\t\t\t\t\t\tPD_UnboxedListType)\n\t#! list_ident = predefined_idents.[pre_def_list_index]\n\t= MakeNewTypeSymbIdent list_ident arity\n\nmakeTailStrictListTypeSymbol :: Int Int -> TypeSymbIdent\nmakeTailStrictListTypeSymbol head_strictness arity\n\t# pre_def_list_index=if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_TailStrictListType\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictTailStrictListType\n\t\t\t\t\t\t\tPD_UnboxedTailStrictListType)\n\t#! list_ident = predefined_idents.[pre_def_list_index]\n\t= MakeNewTypeSymbIdent list_ident arity\n\nmakeLazyArraySymbol arity\n\t#! lazy_array_ident = predefined_idents.[PD_LazyArrayType]\n\t= MakeNewTypeSymbIdent lazy_array_ident arity\n\nmakeStrictArraySymbol arity\n\t#! strict_array_ident = predefined_idents.[PD_StrictArrayType]\n\t= MakeNewTypeSymbIdent strict_array_ident arity\n\nmakeUnboxedArraySymbol arity\n\t#! unboxed_array_ident = predefined_idents.[PD_UnboxedArrayType]\n\t= MakeNewTypeSymbIdent unboxed_array_ident arity\n\nmakeTupleTypeSymbol form_arity act_arity\n\t#! tuple_ident = predefined_idents.[GetTupleTypeIndex form_arity]\n\t= MakeNewTypeSymbIdent tuple_ident act_arity\n\t\nclass try a\t :: !Token !*ParseState -> (!Optional a, !*ParseState)\nclass want a :: !*ParseState -> (!a, !*ParseState)\n\nstringToQualifiedModuleIdent module_name ident_name ident_class pState :== (ident,parse_state)\n\twhere\n\t\t({boxed_ident=ident},parse_state) = stringToQualifiedModuleBoxedIdent module_name ident_name ident_class pState\n\nstringToQualifiedModuleBoxedIdent :: !String !String !IdentClass !*ParseState -> (!BoxedIdent, !*ParseState)\nstringToQualifiedModuleBoxedIdent module_name ident_name ident_class pState=:{ps_hash_table}\n\t# (ident, ps_hash_table) = putIdentInHashTable ident_name ident_class ps_hash_table\n\t# (module_ident, ps_hash_table) = putQualifiedIdentInHashTable module_name ident ident_class ps_hash_table\n\t= (module_ident, {pState & ps_hash_table = ps_hash_table})\n\nstringToIdent s i p :== (ident,parse_state)\n\twhere\n\t\t({boxed_ident=ident},parse_state) = stringToBoxedIdent s i p\n\nstringToBoxedIdent :: !String !IdentClass !*ParseState -> (!BoxedIdent, !*ParseState)\nstringToBoxedIdent ident ident_class pState=:{ps_hash_table}\n\t# (ident, ps_hash_table) = putIdentInHashTable ident ident_class ps_hash_table\n\t= (ident, { pState & ps_hash_table = ps_hash_table } )\n\ninternalIdent s p :== (ident,parse_state)\n\twhere\n\t\t({boxed_ident=ident},parse_state) = internalBoxedIdent s p\n\ninternalBoxedIdent :: !String !*ParseState -> (!BoxedIdent, !*ParseState)\ninternalBoxedIdent prefix pState\n\t# ({fp_line,fp_col},pState=:{ps_hash_table})\t= getPosition pState\n\t case_string\t\t\t\t\t\t\t\t\t= prefix +++ \";\" +++ toString fp_line +++ \";\" +++ toString fp_col\n\t (case_ident, ps_hash_table)\t\t\t\t\t= putIdentInHashTable case_string IC_Expression ps_hash_table\n\t= (case_ident, { pState & ps_hash_table = ps_hash_table } )\n\nerroneousIdent = { id_name = \"\", id_info = nilPtr }\n\n\/*\n\tSome general overloaded parsing routines\n*\/\n\nwantSequence :: !Token !ScanContext !*ParseState -> (!.[a],!*ParseState) | want a\nwantSequence separator scanContext pState\n\t# (first, pState) = want pState\n\t (token, pState) = nextToken scanContext pState\n\t| separator == token\n\t\t# (rest, pState) = wantSequence separator scanContext pState\n\t\t= ([first : rest], pState)\n\t\/\/ otherwise \/\/ separator <> token\n\t= ([first], tokenBack pState)\n\/*\noptionalSequence start_token separator scanContext pState\n\t# (token, pState) = nextToken scanContext pState\n\t| token == start_token\n\t\t= wantSequence separator scanContext pState\n\t\t= ([], tokenBack pState)\n*\/\nparseList try_fun pState :== parse_list pState \/\/ try_fun *\n\/\/parseList try_fun pState = parse_list pState\n\twhere\n\t\/\/\tparse_list :: !*ParseState -> (tree, *ParseState)\n\t\tparse_list pState\n\t\t\t# (succ, tree, pState) = try_fun pState\n\t\t\t| succ\n\t\t\t\t# (trees, pState) = parse_list pState\n\t\t\t\t= ([tree : trees], pState)\n\t\t\t= ([], pState)\n\n\/\/wantSepList msg sep_token scanContext try_fun pState = want_list msg pState\nwantSepList msg sep_token scanContext try_fun pState :== want_list msg pState \/\/ try_fun (sep_token tryfun)*\n\twhere\n\t\twant_list msg pState\n\t\t\t# (succ, tree, pState) = try_fun pState\n\t\t\t| succ\n\t\t\t \t# (token, pState) = nextToken scanContext pState\n\t\t\t \t| token == sep_token\n\t\t\t\t\t# (trees, pState) = optSepList sep_token scanContext try_fun pState\n\t\t\t\t\t= ([tree : trees], pState)\n\t\t\t\t\/\/ otherwise \/\/ token <> sep_token\n\t\t\t\t\t= ([tree], tokenBack pState)\n\t\t\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t\t\t= ([tree], parseError (\"wantList of \"+msg) (Yes token) msg pState)\n\n\/\/optSepList sep_token scanContext try_fun pState = want_list msg pState\noptSepList sep_token scanContext try_fun pState :== want_list pState \/\/ [ try_fun (sep_token tryfun)* ]\n\twhere\n\t\twant_list pState\n\t\t\t# (succ, tree, pState) = try_fun pState\n\t\t\t| succ\n\t\t\t \t# (token, pState) = nextToken scanContext pState\n\t\t\t \t| token == sep_token\n\t\t\t\t\t# (trees, pState) = want_list pState\n\t\t\t\t\t= ([tree : trees], pState)\n\t\t\t\t\/\/ otherwise \/\/ token <> sep_token\n\t\t\t\t\t= ([tree], tokenBack pState)\n\t\t\t= ([], pState)\n\n\/\/wantList msg try_fun pState = want_list msg pState\nwantList msg try_fun pState :== want_list msg pState \/\/ try_fun +\n\twhere\n\t\twant_list msg pState\n\t\t\t# (succ, tree, pState) = try_fun pState\n\t\t\t| succ\n\t\t\t\t# (trees, pState) = parseList try_fun pState\n\t\t\t\t= ([tree : trees], pState)\n\t\t\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t\t\t= ([tree], parseError (\"wantList of \"+msg) (Yes token) msg pState)\n\noptionalPriority :: !Bool !Token !ParseState -> (Priority, !ParseState)\noptionalPriority isinfix (PriorityToken prio) pState\n\t= (prio, pState)\noptionalPriority isinfix token pState\n\t| isinfix\n\t\t= (DefaultPriority, tokenBack pState)\n\t\t= (NoPrio, tokenBack pState)\n\n\/*\n\tModules\n*\/\n\n::\tParseContext\t\t\t:== Int\n\ncICLContext\t\t\t\t\t:== 1\ncGlobalContext\t\t\t\t:== 2\ncDCLContext\t\t\t\t\t:== 0\ncLocalContext\t\t\t\t:== 1\nClassDefsContext\t\t\t:== 4\nInstanceDefsContext\t\t\t:== 8\nGlobalOrClassDefsContext\t:== 6 \/\/ cGlobalContext bitor ClassDefsContext\nClassOrInstanceDefsContext\t:== 12 \/\/ ClassDefsContext bitor InstanceDefsContext\n\/*\n\tA cClassOrInstanceDefsContext is a further restriction on a\n\tlocal context, because no local node defs are allowed\n\tThis context stuff is getting far too complicated.\n\tPossible solution: accept everything in the parser and\n\tdiscriminate in postparse, depending on the context.\n*\/\n\nSetGlobalContext iclmodule\n\t| iclmodule\n\t\t= cICLContext bitor cGlobalContext\n\t\t= cDCLContext bitor cGlobalContext\n\nSetLocalContext\t\t\tparseContext :== parseContext bitand (bitnot cGlobalContext)\nSetClassDefsContext\t\tparseContext :== SetLocalContext (parseContext bitor ClassDefsContext)\nSetInstanceDefsContext\tparseContext :== SetLocalContext (parseContext bitor InstanceDefsContext)\n\nisLocalContext\tparseContext\t:== parseContext bitand cGlobalContext == 0\nisGlobalContext\tparseContext\t:== parseContext bitand cGlobalContext <> 0 \/\/ not (isLocalContext parseContext)\n\nisDclContext\tparseContext\t:== parseContext bitand cICLContext == 0\nisIclContext\tparseContext\t:== parseContext bitand cICLContext <> 0\t\/\/ not (isDclContext parseContext)\n\nisNotClassOrInstanceDefsContext parseContext\t\t:== parseContext bitand ClassOrInstanceDefsContext == 0\nisGlobalOrClassDefsContext parseContext\t\t\t\t:== parseContext bitand GlobalOrClassDefsContext <> 0\nisInstanceDefsContext parseContext\t\t\t\t\t:== parseContext bitand InstanceDefsContext <> 0\n\ncWantIclFile :== True\ncWantDclFile :== False\n\nwantModule :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> (!Bool,!Bool,!ParsedModule, !*HashTable, !*File, !*Files)\nwantModule file modification_time iclmodule file_id=:{id_name} import_file_position support_generics hash_table error files\n\t# scanState = openScanner file id_name file_name_extension\n\t# hash_table = set_hte_mark (if iclmodule 1 0) hash_table\n\t hash_table = remove_qualified_idents_from_hash_table hash_table\n\t# (ok,dynamic_type_used,mod,hash_table,file,files) = initModule file_name modification_time scanState hash_table error files\n\t hash_table=set_hte_mark 0 hash_table\n\t= (ok,dynamic_type_used,mod,hash_table,file,files)\nwhere\n\tfile_name = id_name +++ file_name_extension\n\tfile_name_extension = if iclmodule \".icl\" \".dcl\"\n\n\tinitModule :: String String ScanState !*HashTable !*File *Files\n\t\t\t\t-> (!Bool,!Bool,!ParsedModule,!*HashTable,!*File,!*Files)\n\tinitModule file_name modification_time scanState hash_table error files\n\t\t# (succ, mod_type, mod_name, scanState) = try_module_header iclmodule scanState\n\t\t| succ\n\t\t\t# pState\t\t\t\t=\t{ ps_scanState = scanState\n\t\t\t\t\t\t\t\t\t\t, ps_error = { pea_file = error, pea_ok = True }\n\t\t\t\t\t\t\t\t\t\t, ps_flags = if support_generics PS_SupportGenericsMask 0\n\t\t\t\t\t\t\t\t\t\t, ps_hash_table = hash_table\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t pState\t\t\t\t= verify_name mod_name id_name file_name pState\n\t\t \t (mod_ident, pState)\t= stringToIdent mod_name (IC_Module NoQualifiedIdents) pState\n\t\t \t pState\t\t\t\t= check_layout_rule pState\n\t\t \t (defs, pState)\t\t= want_definitions (SetGlobalContext iclmodule) pState\n\t\t\t {ps_scanState,ps_hash_table,ps_error,ps_flags}\n\t\t\t \t\t\t\t\t\t= pState\n\t\t\t defs = if (ParseOnly && id_name <> \"StdOverloaded\" && id_name <> \"StdArray\" && id_name <> \"StdEnum\" && id_name <> \"StdBool\" && id_name <> \"StdDynamics\" && id_name <> \"StdGeneric\")\n\t\t\t\t\t\t[PD_Import imports \\\\ PD_Import imports <- defs]\n\t\t\t\t\t\tdefs\n\t\t\t mod\t= { mod_ident = mod_ident, mod_modification_time = modification_time, mod_type = mod_type, mod_imports = [], mod_imported_objects = [], mod_foreign_exports=[],mod_defs = defs }\n\t\t\t files = closeScanner ps_scanState files\n\t\t\t= ( ps_error.pea_ok, ps_flags bitand PS_DynamicTypeUsedMask<>0, mod, ps_hash_table, ps_error.pea_file, files)\n\t\t\/\/ otherwise \/\/ ~ succ\n\t\t# ({fp_line}, scanState) = getPosition scanState\n\t\t mod = { mod_ident = file_id, mod_modification_time = modification_time, mod_type = mod_type, mod_imports = [], mod_imported_objects = [],mod_foreign_exports=[],mod_defs = [] }\n\t\t= (False, False, mod, hash_table, error <<< \"Error [\" <<< file_name <<< ',' <<< fp_line <<< \"]: incorrect module header\",\n\t\t\tcloseScanner scanState files)\n\n\ttry_module_header :: !Bool !ScanState -> (!Bool,!ModuleKind,!String,!ScanState)\n\ttry_module_header is_icl_mod scanState\n\t\t# (token, scanState) = nextToken GeneralContext scanState\n\t\t| is_icl_mod\n\t\t\t| token == ModuleToken\n\t\t\t\t# (token, scanState) = nextToken GeneralContext scanState\n\t\t\t\t= try_module_name token MK_Main scanState\n\t\t\t| token == ImpModuleToken \n\t\t\t\t= try_module_token MK_Module scanState\n\t\t\t| token == SysModuleToken\n\t\t\t\t= try_module_token MK_System scanState\n\t\t\t\t= (False, MK_None, \"\", tokenBack scanState)\n\t\t| token == DefModuleToken\n\t\t \t= try_module_token MK_Module scanState\n\t\t| token == SysModuleToken\n\t\t \t= try_module_token MK_System scanState\n\t\t\t= (False, MK_None, \"\", tokenBack scanState)\n\n\ttry_module_token :: !ModuleKind !ScanState -> (!Bool,!ModuleKind,!String,!ScanState)\n\ttry_module_token mod_type scanState\n\t\t# (token, scanState) = nextToken GeneralContext scanState\n\t\t| token == ModuleToken\n\t\t\t# (token, scanState) = nextToken ModuleNameContext scanState\n \t\t\t= try_module_name token mod_type scanState\n\t\t\t= (False, mod_type, \"\", tokenBack scanState)\n\n\ttry_module_name (IdentToken name) mod_type scanState\n\t\t= (True, mod_type, name, scanState)\n\ttry_module_name (UnderscoreIdentToken name) mod_type scanState\n\t\t= (True, mod_type, name, setUseUnderscoreIdents True scanState)\n\ttry_module_name token mod_type scanState\n\t\t= (False, mod_type, \"\", tokenBack scanState)\n\t\n\tverify_name name id_name file_name pState\n\t\t| name == id_name\n\t \t\t= pState\n\t\t\t# ({fp_line}, pState=:{ps_error={pea_file}}) = getPosition pState\n \t\t\t pea_file = pea_file <<< \"Error [\" <<< file_name <<< ',' <<< fp_line <<< \"]: module name \\\"\" <<< name \n\t \t\t\t\t\t\t<<< \"\\\" does not match file name: \\\"\" <<< file_name <<<\"\\\"\\n\"\n\t\t\t= { pState & ps_error = { pea_file = pea_file, pea_ok = False }}\n\n\tcheck_layout_rule pState\n\t\t# (token, pState)\t= nextToken GeneralContext pState\n\t\t use_layout\t\t= token <> SemicolonToken && token <> EndOfFileToken \/\/ '&& token <> EndOfFileToken' to handle end groups of empty modules\n\t\t| use_layout\t\t= appScanState (setUseLayout use_layout) (tokenBack pState)\n\t\t\t\t\t\t\t= appScanState (setUseLayout use_layout) pState\n\n\twant_definitions :: !ParseContext !ParseState -> (![ParsedDefinition], !ParseState)\n\twant_definitions parseContext pState\n\t\t= want_acc_definitions [] pState\n\twhere\n\t\twant_acc_definitions :: ![ParsedDefinition] !ParseState -> (![ParsedDefinition], !ParseState)\n\t\twant_acc_definitions acc pState\n\t\t\t# (defs, pState)\t= wantDefinitions parseContext pState\n\t\t\t acc\t\t\t\t= acc ++ defs\n\t\t\t pState\t\t\t= wantEndModule pState\n\t\t\t (token, pState)\t= nextToken FunctionContext pState\n\t\t\t| token == EndOfFileToken\n\t\t\t\t= (acc, pState)\n\t\t\t\t# pState\t\t= parseError \"want definitions\" (Yes token) \"End of file\" pState\n\t\t\t\t pState\t\t= wantEndOfDefinition \"definitions\" pState\n\t\t\t\t= want_acc_definitions acc pState\n\nmoduleCouldNotBeImportedError :: !Bool !Ident !Position !*File -> *File\nmoduleCouldNotBeImportedError iclmodule file_id=:{id_name} import_file_position error\n\t# file_name_extension = if iclmodule \".icl\" \".dcl\"\n\t file_name = id_name +++ file_name_extension\n\t= error <<< \"Error \" <<< import_file_position <<< \": \" <<< file_name <<< \" could not be imported\\n\"\n\n\/*\n\t[Definition] on local and global level\n*\/\n\nwantDefinitions :: !ParseContext !ParseState -> (![ParsedDefinition], !ParseState)\nwantDefinitions parseContext pState\n\t= parseList (tryDefinition parseContext) pState\n\ncHasPriority \t:== True\ncHasNoPriority\t:== False\n\ntryDefinition :: !ParseContext !ParseState -> (!Bool, ParsedDefinition, !ParseState)\ntryDefinition parseContext pState\n\t# (token, pState)\t\t\t= nextToken GeneralContext pState\n\t (fname, linenr, pState)\t= getFileAndLineNr pState\n\t= try_definition parseContext token (LinePos fname linenr) pState\nwhere\n\ttry_definition :: !ParseContext !Token !Position !ParseState -> (!Bool, ParsedDefinition, !ParseState)\n\ttry_definition parseContext DoubleColonToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(3)\",parseError \"definition\" No \"type definitions only at the global level\" (tokenBack pState))\n\t\t\t# (def, pState) = wantTypeDef parseContext pos pState\n\t\t\t= (True, def, pState)\n\ttry_definition parseContext (IdentToken name) pos pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tGenericOpenToken\n\t\t\t\t\/\/ generic function\n\t\t\t\t-> wantGenericFunctionDefinition name pos pState\n\t\t\t_ \/\/ normal function\n\t\t\t\t# pState = tokenBack pState\n\t\t\t\t# (lhs, pState) = want_lhs_of_def (IdentToken name) pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (def, pState) = want_rhs_of_def parseContext lhs token (determine_position lhs pos) pState\n\t\t\t\t-> (True, def, pState)\n\ttry_definition _ ImportToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(3)\",parseError \"definition\" No \"imports only at the global level\" pState)\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == CodeToken && isIclContext parseContext\n\t\t\t# (importedObjects, pState) = wantCodeImports pState\n\t\t\t= (True, PD_ImportedObjects importedObjects, pState)\n\t\t\t# pState = tokenBack pState\n\t\t\t# (imports, pState) = wantImports pState\n\t \t\t= (True, PD_Import imports, pState)\n\ttry_definition _ FromToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(3)\",parseError \"definition\" No \"imports only at the global level\" pState)\n\t\t\t# (imp, pState) = wantFromImports pState\n\t \t\t= (True, PD_Import [imp], pState)\n\ttry_definition parseContext ClassToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(2)\",parseError \"definition\" No \"class definitions are only at the global level\" pState)\n\t \t\t# (classdef, pState) = wantClassDefinition parseContext pos pState\n\t \t\t= (True, classdef, pState)\n\ttry_definition parseContext GenericToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(2)\",parseError \"definition\" No \"generic definitions are only at the global level\" pState)\n\t \t\t# (gendef, pState) = wantGenericDefinition parseContext pos pState\n\t \t\t= (True, gendef, pState)\n\ttry_definition parseContext DeriveToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(2)\",parseError \"definition\" No \"derive declarations are only at the global level\" pState) \t\t\n\t \t\t# (gendef, pState) = wantDeriveDefinition parseContext pos pState\n\t \t\t= (True, gendef, pState)\n\ttry_definition parseContext InstanceToken pos pState\n\t\t| ~(isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def(2)\",parseError \"definition\" No \"instance declarations are only at the global level\" pState)\n\t \t\t# (instdef, pState) = wantInstanceDeclaration parseContext pos pState\n\t \t\t= (True, instdef, pState)\n\ttry_definition parseContext ForeignToken pos pState\n\t\t| not (isGlobalContext parseContext)\n\t\t\t= (False,abort \"no def\",parseErrorSimple \"definition\" \"foreign export definitions are only allowed at the global level\" pState)\n\t\t| isDclContext parseContext\n\t\t\t= (False,abort \"no def\",parseErrorSimple \"definition\" \"foreign export definitions are only allowed in implementation modules\" pState)\n\t\t\t= wantForeignExportDefinition pState\n\ttry_definition parseContext token pos pState\n\t\t| isLhsStartToken token\n\t\t\t# (lhs, pState) = want_lhs_of_def token pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t (def, pState) = want_rhs_of_def parseContext lhs token (determine_position lhs pos) pState\n\t\t\t= (True, def, pState)\n\t\t= (False, abort \"no def(1)\", tokenBack pState)\n\n\tdetermine_position (Yes (name, _), _)\t(LinePos f l) = FunPos f l name.id_name\n\tdetermine_position lhs \t\tpos = pos\n\n\twant_lhs_of_def :: !Token !ParseState -> (!(Optional (Ident, Bool), ![ParsedExpr]), !ParseState)\n\twant_lhs_of_def token pState\n\t\t# (succ, fname, is_infix, pState) = try_function_symbol token pState\n\t\t| succ\n\t\t\t# (args, pState) = parseList trySimplePattern pState\n\t\t\t= ((Yes (fname, is_infix), args), pState)\n\t\t\t# (_, exp, pState) = trySimplePattern pState\n\t\t\t= ((No, [exp]), pState)\n\twhere\n\t\ttry_function_symbol :: !Token !ParseState -> (!Bool, Ident, !Bool, !ParseState) \/\/ (Success, Ident, Infix, ParseState)\n\t\ttry_function_symbol (IdentToken name) pState\n\t\t\t# (id, pState) = stringToIdent name IC_Expression pState\n\t\t\t= (True, id, False, pState)\n\t\ttry_function_symbol OpenToken pState\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t= case token of\n\t\t\t\tIdentToken name\n\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t| CloseToken == token\n\t\t\t\t\t\t# (id, pState) = stringToIdent name IC_Expression pState\n\t\t\t\t\t\t-> (True, id, True, pState)\n\t\t\t\t\t\t-> (False, abort \"no name\", False, tokenBack (tokenBack (tokenBack pState)))\n\t\t\t\t_\n\t\t\t\t\t-> (False, abort \"no name\", False, tokenBack (tokenBack pState))\n\t\ttry_function_symbol token pState\n\t\t\t= (False, abort \"name\", False, tokenBack pState)\n\n\twant_rhs_of_def :: !ParseContext !(Optional (Ident, Bool), [ParsedExpr]) !Token !Position !ParseState -> (ParsedDefinition, !ParseState)\n\twant_rhs_of_def parseContext (opt_name, []) DoubleColonToken pos pState\n\t\t# (name, is_infix, pState) = check_name_and_fixity opt_name cHasNoPriority pState\n\t\t (tspec, pState) = wantSymbolType pState\n\t\t| isDclContext parseContext\n\t\t\t# (specials, pState) = optionalFunSpecials pState\n\t\t\t= (PD_TypeSpec pos name (if is_infix DefaultPriority NoPrio) (Yes tspec) specials, wantEndOfDefinition \"type definition\" pState)\n\t\t\t= (PD_TypeSpec pos name (if is_infix DefaultPriority NoPrio) (Yes tspec) FSP_None, wantEndOfDefinition \"type definition\" pState)\n\twant_rhs_of_def parseContext (opt_name, args) (PriorityToken prio) pos pState\n\t\t# (name, _, pState) = check_name_and_fixity opt_name cHasPriority pState\n\t\t (token, pState) = nextToken TypeContext pState\n\t\t| token == DoubleColonToken\n\t\t \t# (tspec, pState) = wantSymbolType pState\n\t\t\t| isDclContext parseContext\n\t\t\t\t# (specials, pState) = optionalFunSpecials pState\n\t\t\t\t= (PD_TypeSpec pos name prio (Yes tspec) specials, wantEndOfDefinition \"type definition\" pState)\n\t\t\t\t= (PD_TypeSpec pos name prio (Yes tspec) FSP_None, wantEndOfDefinition \"type definition\" pState)\n\t\t\t= (PD_TypeSpec pos name prio No FSP_None, wantEndOfDefinition \"type definition\" (tokenBack pState))\n\twant_rhs_of_def parseContext (No, args) token pos pState\n\t\t# pState\t\t\t= want_node_def_token pState token\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t localsExpected\t= ~ ss_useLayout\n\t\t (rhs, _, pState)\t\t= wantRhs localsExpected (ruleDefiningRhsSymbol parseContext (isNotEmpty args)) (tokenBack pState)\n\t\t| isLocalContext parseContext\n\t\t\t| isNotClassOrInstanceDefsContext parseContext\n \t\t\t\t= (PD_NodeDef pos (combine_args args) rhs, pState)\n\t \t\t\t= (PD_NodeDef pos (combine_args args) rhs, parseError \"RHS\" No \"\" pState)\n\t\t\t= (PD_NodeDef pos (combine_args args) rhs, parseError \"RHS\" No \"\" pState)\n\twhere\t\t\n\t\twant_node_def_token s EqualToken\t\t= s\n\t\twant_node_def_token s token\t\t\t\t= parseError \"RHS\" (Yes token) \"defines token (=)\" s\n\n\t\tcombine_args [arg]\t= arg\n\t\tcombine_args args\t= PE_List args\n\twant_rhs_of_def parseContext (Yes (name, False), []) definingToken pos pState\n\t\t# code_allowed = definingToken == EqualToken\n\t\t| isIclContext parseContext && isLocalContext parseContext && (definingToken == EqualToken || (definingToken == DefinesColonToken && isGlobalContext parseContext)) &&\n\t\t\/* PK isLowerCaseName name.id_name && *\/ isNotClassOrInstanceDefsContext parseContext\n\t\t \t# (token, pState) = nextToken FunctionContext pState\n\t\t\t| code_allowed && token == CodeToken\n\t\t\t\t# (rhs, pState) = wantCodeRhs pState\n\t\t\t\t= (PD_Function pos name False [] rhs (FK_Function cNameNotLocationDependent), pState)\n\t\t\t# pState = tokenBack pState\n\t\t\t# (rhs, _, pState) = wantRhs False (RhsDefiningSymbolExact definingToken) (tokenBack pState)\n\t\t\t| token == EqualToken\n\t\t\t\t= (PD_Function pos name False [] rhs FK_NodeDefOrFunction, pState)\n\t\t\t\/\/ otherwise \/\/ token == DefinesColonToken\n \t\t\t\t| isGlobalContext parseContext\n\t\t\t\t\t= (PD_Function pos name False [] rhs FK_Caf, pState)\n\t\t\t\t\/\/ otherwise\n\t\t\t\t\t= (PD_NodeDef pos (PE_Ident name) rhs, pState)\n\twant_rhs_of_def parseContext (Yes (name, is_infix), args) token pos pState\n\t\t# code_allowed = token == EqualToken || token == DoubleArrowToken\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| isIclContext parseContext && token == CodeToken\n\t\t\t# (rhs, pState) = wantCodeRhs pState\n\t\t\t| code_allowed\n\t\t\t\t= (PD_Function pos name is_infix args rhs (FK_Function cNameNotLocationDependent), pState)\n\t\t\t\/\/ otherwise \/\/ ~ code_allowed\n\t\t\t\t= (PD_Function pos name is_infix args rhs (FK_Function cNameNotLocationDependent), parseError \"rhs of def\" No \"no code\" pState)\n\t\t# pState = tokenBack (tokenBack pState)\n\t\t (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t has_args = isNotEmpty args\n\t\t localsExpected = has_args || isGlobalContext parseContext || ~ ss_useLayout\n\t\t (rhs, defining_symbol, pState)\n\t\t \t\t= wantRhs localsExpected (ruleDefiningRhsSymbol parseContext has_args) pState\n\t\t fun_kind = definingSymbolToFunKind defining_symbol\n\t\t= case fun_kind of\n\t\t\tFK_Function _ | isDclContext parseContext\n\t\t\t\t->\t(PD_Function pos name is_infix args rhs fun_kind, parseError \"RHS\" No \"\" pState)\n\t\t\tFK_Caf | isNotEmpty args\n\t\t\t\t->\t(PD_Function pos name is_infix [] rhs fun_kind, parseError \"CAF\" No \"No arguments for a CAF\" pState)\n\t\t\t_\t->\t(PD_Function pos name is_infix args rhs fun_kind, pState)\n\n\twantGenericFunctionDefinition name pos pState\n\t\t\/\/# (type, pState) = wantType pState\n\t\t# (ok, {at_type=type}, pState) = trySimpleType TA_None pState\n\t\t# (ident, pState) = stringToIdent name (IC_GenericCase type) pState\n\t\t# (generic_ident, pState) = stringToIdent name IC_Generic pState\t\n\t\t# (type_cons, generic_fun_ident, pState) = get_type_cons type pState\n\t\t\twith\n\t\t\t\tget_type_cons (TA type_symb []) pState\n\t\t\t\t\t= make_generic_fun_ident (TypeConsSymb type_symb) pState\n\t\t\t\tget_type_cons (TA type_symb _) pState\n\t\t\t\t\t# pState = parseError \"generic type, no constructor arguments allowed\" No \" |}\" pState\n\t\t\t\t\t= (abort_no_TypeCons, abort_no_TypeCons, pState)\n\t\t\t\tget_type_cons (TB tb) pState\n\t\t\t\t\t= make_generic_fun_ident (TypeConsBasic tb) pState\n\t\t\t\tget_type_cons TArrow pState\n\t\t\t\t\t= make_generic_fun_ident TypeConsArrow pState\n\t\t\t\tget_type_cons (TV tv) pState\n\t\t\t\t\t= make_generic_fun_ident (TypeConsVar tv) pState\n\t\t\t\tget_type_cons _ pState \n\t\t\t\t\t# pState = parseError \"generic type\" No \" |}\" pState\n\t\t\t\t\t= (abort_no_TypeCons, abort_no_TypeCons, pState)\n\t\t\t\t\n\t\t\t\tmake_generic_fun_ident type_cons pState\n\t\t\t\t\t# generic_fun_ident = genericIdentToFunIdent name type_cons\n\t\t\t\t\t (generic_fun_ident,pState) = stringToIdent generic_fun_ident.id_name IC_Expression pState\n\t\t\t\t\t= (type_cons, generic_fun_ident, pState)\n\n\t\t# (token, pState) = nextToken GenericContext pState\n\t\t# (geninfo_arg, gcf_generic_info, pState) = case token of\n\t\t\tGenericOfToken\n\t\t\t\t# (ok, geninfo_arg, pState) = trySimplePattern pState\n\t\t\t\t# pState = wantToken FunctionContext \"type argument\" GenericCloseToken pState\n\t\t\t\t| ok \n\t\t\t\t\t-> case type_cons of\n\t\t\t\t\t\tTypeConsSymb {type_ident=type_ident=:{id_name}}\n\t\t\t\t\t\t\t| id_name==\"OBJECT\"\n\t\t\t\t\t\t\t\t# (generic_constructor_type_ident, pState) = stringToIdent id_name IC_Type pState\n\t\t\t\t\t\t\t\t| type_ident==generic_constructor_type_ident\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, generic_info_of_OBJECT_geninfo_arg geninfo_arg, pState)\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, 0, pState)\n\t\t\t\t\t\t\t| id_name==\"CONS\"\n\t\t\t\t\t\t\t\t# (generic_constructor_type_ident, pState) = stringToIdent id_name IC_Type pState\n\t\t\t\t\t\t\t\t| type_ident==generic_constructor_type_ident\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, generic_info_of_CONS_geninfo_arg geninfo_arg, pState)\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, 0, pState)\n\t\t\t\t\t\t\t| id_name==\"RECORD\"\n\t\t\t\t\t\t\t\t# (generic_constructor_type_ident, pState) = stringToIdent id_name IC_Type pState\n\t\t\t\t\t\t\t\t| type_ident==generic_constructor_type_ident\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, generic_info_of_RECORD_geninfo_arg geninfo_arg, pState)\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, 0, pState)\n\t\t\t\t\t\t\t| id_name==\"FIELD\"\n\t\t\t\t\t\t\t\t# (generic_constructor_type_ident, pState) = stringToIdent id_name IC_Type pState\n\t\t\t\t\t\t\t\t| type_ident==generic_constructor_type_ident\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, generic_info_of_FIELD_geninfo_arg geninfo_arg, pState)\n\t\t\t\t\t\t\t\t\t-> (geninfo_arg, 0, pState)\n\t\t\t\t\t\t_\n\t\t\t\t\t\t\t-> (geninfo_arg, 0, pState)\n\t\t\t\t| otherwise\n\t\t\t\t\t# pState = parseError \"generic case\" No \"simple lhs expression\" pState\n\t\t\t\t\t-> (PE_Empty, 0, pState)\n\n\t\t\tGenericCloseToken\n\t\t\t\t-> (PE_WildCard, 0, pState)\n\t\t\t_ \t\n\t\t\t\t# pState = parseError \"generic type\" (Yes token) \"of or |}\" pState\n\t\t\t\t-> (PE_WildCard, 0, pState)\n\n\t\t\/\/# pState = wantToken FunctionContext \"type argument\" GenericCloseToken pState\n\t\t# (args, pState) = parseList trySimplePattern pState\n\t \t# has_args = isNotEmpty args || gcf_generic_info<>0\n\t\t# args = [geninfo_arg : args]\n\n\t \t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t # localsExpected = has_args || isGlobalContext parseContext || ~ ss_useLayout\n\t # (rhs, _, pState) = wantRhs localsExpected (ruleDefiningRhsSymbol parseContext has_args) pState\n\n\t\t# generic_case =\n\t\t\t{ gc_pos = pos\n\t\t\t, gc_type = type\n\t\t\t, gc_type_cons = type_cons\n\t\t\t, gc_gcf = GCF ident {\n\t\t\t\t\t\tgcf_gident = generic_ident,\n\t\t\t\t\t\tgcf_generic = {gi_module=NoIndex,gi_index=NoIndex},\n\t\t\t\t\t\tgcf_arity = length args,\n\t\t\t\t\t\tgcf_generic_info = gcf_generic_info,\n\t\t\t\t\t\tgcf_body = GCB_ParsedBody args rhs,\n\t\t\t\t\t\tgcf_kind = KindError,\n\t\t\t\t\t\tgcf_generic_instance_deps = AllGenericInstanceDependencies }\n\t\t\t}\n\t\t= (True, PD_GenericCase generic_case generic_fun_ident, pState)\n\n\tabort_no_TypeCons => abort \"no TypeCons\"\n\n\twantForeignExportDefinition pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t# (file_name,line_nr,pState) = getFileAndLineNr pState\n\t\t= case token of\n\t\t\tIdentToken \"export\"\n\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t-> case token of\n\t\t\t\t\tIdentToken function_name\n\t\t\t\t\t\t| function_name==\"ccall\"\n\t\t\t\t\t\t\t# (token2, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t-> case token2 of\n\t\t\t\t\t\t\t\tIdentToken function_name\n\t\t\t\t\t\t\t\t\t-> accept_foreign_export function_name line_nr False pState\n\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t-> accept_foreign_export function_name line_nr False (tokenBack pState)\n\t\t\t\t\t\t| function_name==\"stdcall\"\n\t\t\t\t\t\t\t# (token2, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t-> case token2 of \n\t\t\t\t\t\t\t\tIdentToken function_name\n\t\t\t\t\t\t\t\t\t-> accept_foreign_export function_name line_nr True pState\n\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t-> accept_foreign_export function_name line_nr False (tokenBack pState)\n\t\t\t\t\t\t\t-> accept_foreign_export function_name line_nr False pState\n\t\t\t\t\t_\n\t\t\t\t\t\t-> foreign_export_error \"function name\" pState\n\t\t\t\twhere\n\t\t\t\t\taccept_foreign_export function_name line_nr stdcall pState\n\t\t\t\t\t\t# pState = wantEndOfDefinition \"foreign export\" pState\n\t\t\t\t\t\t# (ident,pState) = stringToIdent function_name IC_Expression pState\n\t\t\t\t\t\t= (True,PD_ForeignExport ident file_name line_nr stdcall,pState)\n\t\t\t_\n\t\t\t\t-> foreign_export_error \"export\" pState\n\t\twhere\n\t\t\tforeign_export_error s pState\n\t\t\t\t= (True,PD_Erroneous,tokenBack (parseError \"foreign export\" No s pState))\n\ngeneric_info_of_RECORD_geninfo_arg (PE_Record PE_Empty NoRecordName field_assignments)\n\t= mark_GenericRecordDescriptor_fields field_assignments 0\n where\n\tmark_GenericRecordDescriptor_fields :: [FieldAssignment] !Int -> Int \n\tmark_GenericRecordDescriptor_fields [{bind_dst=FieldName {id_name}}:field_assignments] generic_info\n\t\t# field_number=field_n_of_GenericRecordDescriptor id_name\n\t\t| field_number>=0 && generic_info bitand (1< Int \n\tmark_GenericTypeDefDescriptor_fields [{bind_dst=FieldName {id_name}}:field_assignments] generic_info\n\t\t# field_number=field_n_of_GenericTypeDefDescriptor id_name\n\t\t| field_number>=0 && generic_info bitand (1< Int\n\tmark_GenericConsDescriptor_fields [{bind_dst=FieldName {id_name}}:field_assignments] generic_info\n\t\t# field_number=field_n_of_GenericConsDescriptor id_name\n\t\t| field_number>=0 && generic_info bitand (1< Int\n\tmark_GenericFieldDescriptor_fields [{bind_dst=FieldName {id_name}}:field_assignments] generic_info\n\t\t# field_number=field_n_of_GenericFieldDescriptor id_name\n\t\t| field_number>=0 && generic_info bitand (1< (![ParsedDefinition], !ParseState)\nwant_instance_type_definitions instance_type pState\n\t= parseList want_instance_type_definition pState\nwhere\n\twant_instance_type_definition :: !ParseState -> (!Bool, ParsedDefinition, !ParseState)\n\twant_instance_type_definition pState\n\t\t# (token, pState)\t\t\t= nextToken GeneralContext pState\n\t\t (fname, linenr, pState)\t= getFileAndLineNr pState\n\t\t pos = LinePos fname linenr\n\t\t| isLhsStartToken token\n\t\t\t# (lhs, pState) = want_lhs_of_def token pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (def, pState) = want_rhs_of_instance_member_def lhs token (determine_position lhs pos) pState\n\t\t\t= (True, def, pState)\n\t\t= (False, abort \"no def(1)\", tokenBack pState)\n\twhere\n\t\tdetermine_position (Yes (name, _))\t(LinePos f l) = FunPos f l name.id_name\n\t\tdetermine_position lhs \tpos = pos\n\n\twant_lhs_of_def :: !Token !ParseState -> (!Optional (Ident, Bool), !ParseState)\n\twant_lhs_of_def token pState\n\t\t# (succ, fname, is_infix, pState) = try_function_symbol token pState\n\t\t| succ\n\t\t\t# (function_ident, pState) = stringToIdent fname (IC_InstanceMember instance_type) pState\n\t\t\t= (Yes (function_ident, is_infix), pState)\n\t\t\t= (No, pState)\n\twhere\n\t\ttry_function_symbol :: !Token !ParseState -> (!Bool, {#Char}, !Bool, !ParseState)\n\t\ttry_function_symbol (IdentToken name) pState\n\t\t\t= (True, name, False, pState)\n\t\ttry_function_symbol OpenToken pState\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t= case token of\n\t\t\t\tIdentToken name\n\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t| CloseToken == token\n\t\t\t\t\t\t-> (True, name, True, pState)\n\t\t\t\t\t\t-> (False, abort \"no name\", False, tokenBack (tokenBack (tokenBack pState)))\n\t\t\t\t_\n\t\t\t\t\t-> (False, abort \"no name\", False, tokenBack (tokenBack pState))\n\t\ttry_function_symbol token pState\n\t\t\t= (False, abort \"name\", False, tokenBack pState)\n\n\tcheck_name No pState\n\t\t= (erroneousIdent, NoPrio, parseError \"Definition\" No \"identifier\" pState)\n\tcheck_name (Yes (name,False)) pState\n\t\t= (name, NoPrio, pState)\n\tcheck_name (Yes (name,is_infix)) pState\n\/\/\t\t= (name, DefaultPriority, pState)\n\t\t= (name, Prio NoAssoc 9, pState)\n\n\twant_rhs_of_instance_member_def :: !(Optional (Ident, Bool)) !Token !Position !ParseState -> (ParsedDefinition, !ParseState)\n\twant_rhs_of_instance_member_def opt_name DoubleColonToken pos pState\n\t\t# (name, priority, pState) = check_name opt_name pState\n\t\t (tspec, pState) = wantSymbolType pState\n\t\t= (PD_TypeSpec pos name priority (Yes tspec) FSP_None, wantEndOfDefinition \"type definition\" pState)\n\twant_rhs_of_instance_member_def opt_name (PriorityToken prio) pos pState\n\t\t# (name,_,pState) = check_name_and_fixity opt_name cHasPriority pState\n\t\t (token, pState) = nextToken TypeContext pState\n\t\t| token == DoubleColonToken\n\t\t \t# (tspec, pState) = wantSymbolType pState\n\t\t\t= (PD_TypeSpec pos name prio (Yes tspec) FSP_None, wantEndOfDefinition \"type definition\" pState)\n\t\t\t# pState = parseError \"type definition\" (Yes token) \"::\" pState\n\t\t\t= (PD_TypeSpec pos name prio No FSP_None, wantEndOfDefinition \"type defenition\" pState)\n\twant_rhs_of_instance_member_def opt_name token pos pState\n\t\t# pState = parseError \"type definition\" (Yes token) \"::\" pState\n\t\t= (PD_Erroneous, wantEndOfDefinition \"type defenition\" pState)\n\ncheck_name_and_fixity No hasprio pState\n\t= (erroneousIdent, False, parseError \"Definition\" No \"identifier\" pState)\ncheck_name_and_fixity (Yes (name,is_infix)) hasprio pState\n\t| not is_infix\t&& hasprio\n\t\t= (name, False, parseError \"Definition\" No \"Infix operator should be inside parentheses; no infix\" pState)\n\t\t= (name, is_infix, pState)\n\noptionalSpecials :: !ParseState -> (!Specials, !ParseState)\noptionalSpecials pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == SpecialToken\n\t\t# (specials, pState) = wantSpecials pState\n\t\t= (SP_ParsedSubstitutions specials, pState)\n\t\t= (SP_None, tokenBack pState)\n\noptionalFunSpecials :: !ParseState -> (!FunSpecials, !ParseState)\noptionalFunSpecials pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == SpecialToken\n\t\t# (specials, pState) = wantSpecials pState\n\t\t= (FSP_ParsedSubstitutions specials, pState)\n\t\t= (FSP_None, tokenBack pState)\n\nwantSpecials :: !ParseState -> (![Env Type TypeVar], !ParseState)\nwantSpecials pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t pState = begin_special_group token pState\n\t (specials, pState) = wantList \"\" try_substitutions pState\n\t= (specials, end_special_group pState)\nwhere\n\ttry_substitutions pState\n\t\t# (succ, type_var, pState) = tryTypeVar pState\n\t\t| succ\n\t\t\t# (subst, pState) = want_rest_substitutions type_var pState\n\t\t\t= (True, subst, wantEndOfDefinition \"substitution\" pState)\n\t\t\t= (False, [], pState)\n\n\twant_rest_substitutions type_var pState\n\t\t# pState = wantToken GeneralContext \"specials\" EqualToken pState\n\t\t (type, pState) = want pState\n\t\t (token, pState) = nextToken GeneralContext pState\n\t\t| token == CommaToken\n\t\t\t# (next_type_var, pState) = want pState\n\t\t\t (substs, pState) = want_rest_substitutions next_type_var pState\n\t\t\t= ([{ bind_src = type, bind_dst = type_var } : substs], pState)\n\t\t\t= ([{ bind_src = type, bind_dst = type_var }], tokenBack pState)\n\n\tbegin_special_group token pState \/\/ For JvG layout\n\t\t# (token, pState)\n\t\t\t= case token of\n\t\t\t\tSemicolonToken\t->\tnextToken TypeContext pState\n\t\t\t\t_\t\t\t\t->\t(token, pState)\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t| ss_useLayout\n\t\t\t| token == CurlyOpenToken \n\t\t\t\t= parseError \"substitution\" (Yes CurlyOpenToken) \"in layout mode the keyword where is\" pState\n\t\t\t\/\/ otherwise\n\t\t\t\t= tokenBack pState\n\t\t\/\/ not ss_useLayout\n\t\t\t| token == CurlyOpenToken \n\t\t\t\t= pState\n\t\t\t\/\/ otherwise\n\t\t\t\t= tokenBack (parseError \"substitution\" (Yes token) \"{\" pState) \n\n\tend_special_group pState\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| token == EndOfFileToken && ss_useLayout\n\t\t\t= tokenBack pState\n\t\t| ss_useLayout\n\t\t\t= case token of\n\t\t\t\tEndGroupToken\t->\tpState\n\t\t\t\t_\t\t\t\t->\tparseError \"substitution\" (Yes token) \"end of substitution with layout\" pState\n\t\t\/\/ ~ ss_useLayout\n\t\t| token == CurlyCloseToken\n\t\t\t= pState\n\t\t\/\/ otherwise \/\/ token <> CurlyCloseToken\n\t\t\t= parseError \"substitution\" (Yes token) \"end of substitution with layout, },\" pState\n\n\/*\n\tFor parsing right-hand sides of functions only\n*\/\n\nwantCodeRhs :: !ParseState -> (Rhs, !ParseState)\nwantCodeRhs pState\n\t# (expr, pState)\t= want_code_expr pState\n\t (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t= (\t{ rhs_alts\t\t= UnGuardedExpr\n\t\t\t\t\t\t\t{ ewl_nodes\t\t= []\n\t\t\t\t\t\t\t, ewl_locals\t= LocalParsedDefs []\n\t\t\t\t\t\t\t, ewl_expr\t\t= expr\n\t\t\t\t\t\t\t, ewl_position\t= LinePos file_name line_nr\n\t\t\t\t\t\t\t}\n\t\t, rhs_locals\t= LocalParsedDefs []\n\t\t}\n\t , wantEndCodeRhs pState\n\t )\nwhere\n\twant_code_expr :: !ParseState -> (!ParsedExpr, !ParseState)\n\twant_code_expr pState\n\t\t# (token, pState) = nextToken CodeContext pState\n\t\t= case token of\n\t\t\tOpenToken\n\t\t\t\t#\t(input, pState)\t= want_bindings [] True pState\n\t\t\t\t\tpState\t\t\t= wantToken CodeContext \"input bindings of code block\" CloseToken pState\n\t\t\t\t\tpState\t\t\t= wantToken CodeContext \"output bindings of code block\" OpenToken pState\n\t\t\t\t\t(out, pState)\t= want_bindings [] False pState\n\t\t\t\t\tpState\t\t\t= wantToken CodeContext \"output bindings of code block\" CloseToken pState\n\t\t\t\t\t(token, pState)\t= nextToken CodeContext pState\n\t\t\t\t->\tcase token of\n\t\t\t\t\t\tCodeBlockToken the_code\n\t\t\t\t\t\t\t-> (PE_Any_Code input out the_code, pState)\n\t\t\t\t\t\t_\t-> (PE_Any_Code input out [] , parseError \"code rhs (any code)\" (Yes token) \"code block\" pState)\n\t\t\tInlineToken\n\t\t\t \t#\t(token, pState) = nextToken CodeContext pState\n\t\t\t \t->\tcase token of\n\t\t\t \t\t\tCodeBlockToken the_code\n\t\t\t \t\t\t\t-> (PE_ABC_Code the_code True, pState)\n\t\t\t \t\t\ttoken\n\t\t\t \t\t\t\t-> (PE_ABC_Code [] True, parseError \"inline code\" (Yes token) \"code block\" pState)\n\t\t\tCodeBlockToken the_code\n\t\t\t\t-> (PE_ABC_Code the_code False, pState)\n\t\t\ttoken\n\t\t\t\t-> (PE_Empty, parseError \"code rhs\" (Yes token) \"\" pState)\n\n\twant_bindings :: !(CodeBinding Ident) !Bool !ParseState -> (!CodeBinding Ident, !ParseState)\n\twant_bindings acc mayBeEmpty pState\n\t\t# (token, pState)\t= nextToken CodeContext pState\n\t\t= case token of\n\t\t\tIdentToken name\n\t\t\t\t#\t(token, pState)\t= nextToken CodeContext pState\n\t\t\t\t|\ttoken == EqualToken\n\t\t\t\t\t#\t(token, pState)\t= nextToken CodeContext pState\n\t\t\t\t\t->\tcase token of\n\t\t\t\t\t\t\tIdentToken value\n\t\t\t\t\t\t\t\t#\t(ident, pState)\t= stringToIdent name IC_Expression pState\n\t\t\t\t\t\t\t\t\tacc\t\t\t\t= [{ bind_dst = ident, bind_src = value }: acc]\n\t\t\t\t\t\t\t\t\t(token, pState)\t= nextToken CodeContext pState\n\t\t\t\t\t\t\t\t|\ttoken == CommaToken\n\t\t\t\t\t\t\t\t\t->\twant_bindings acc mayBeEmpty pState\n\t\t\t\t\t\t\t\t\/\/\ttoken <> CommaToken\n\t\t\t\t\t\t\t\t\t->\t(reverse acc, tokenBack pState)\n\t\t\t\t\t\t\ttoken\n\t\t\t\t\t\t\t\t-> (acc, parseError \"bindings in code block\" (Yes token) \"value\" pState)\n\t\t\t\t\/\/\ttoken <> EqualToken\n\t\t\t\t\t->\t(acc, parseError \"bindings in code block\" (Yes token) \"= or =:\" pState)\n\t\t\tCloseToken\n\t\t\t\t| mayBeEmpty\n\t\t\t\t\t-> (acc, tokenBack pState) \/\/ to handle empty input bindings\n\t\t\t\t\t-> (acc, parseError \"code bindings\" (Yes token) \"output bindings\" pState)\n\t\t\ttoken\n\t\t\t\t-> (acc, parseError \"bindings in code block\" (Yes token) \"identifier\" pState)\n\/*\n\tFor parsing right-hand sides of functions and case expressions\n*\/\n\/* Syntax:\n\tFunctionAltDefRhs\t=\tFunctionBody\t\t\t\t\t\t\/\/ Rhs\n\t\t\t\t\t\t\t[ LocalFunctionAltDefs ]\n\tFunctionBody\t\t=\texprWithLocals\t\t\t\t\t\t\/\/ OptGuardedAlts\t: GuardedAlts\n\t\t\t\t\t\t|\tGuardedAlts \t\t\t\t\t\t\/\/\t\t\t\t\t: UnGuardedExpr\n\tGuardedAlts\t\t\t=\t{ [ LetBefore ] '|' [ StrictLet ] Guard FunctionBody }+ [ ExprWithLocals ]\n\tExprWithLocals\t\t=\t[ LetBefore ] sep RootExpression endOfDefinition [ LocalFunctionDefs ]\n*\/\n\n:: RhsDefiningSymbol\n\t=\tRhsDefiningSymbolExact Token\n\t|\tRhsDefiningSymbolCase\t\t\t\/\/ '->' or '='\n\t|\tRhsDefiningSymbolGlobalFunction\t\/\/ '=', '=:', '=>'\n\t|\tRhsDefiningSymbolGlobalFunctionOrMacro\t\/\/ '=', '=:', '=>', ':=='\n\t|\tRhsDefiningSymbolRule\t\t\t\/\/ '=', '=>'\n\t|\tRhsDefiningSymbolRuleOrMacro\t\/\/ '=', '=>', ':=='\n\nruleDefiningRhsSymbol :: !ParseContext !Bool -> RhsDefiningSymbol\nruleDefiningRhsSymbol parseContext has_args\n\t| isGlobalOrClassDefsContext parseContext\n\t\t| has_args\n\t\t\t= RhsDefiningSymbolRuleOrMacro\n\t\t\t= RhsDefiningSymbolGlobalFunctionOrMacro\n\t| isInstanceDefsContext parseContext\n\t\t| has_args\n\t\t\t= RhsDefiningSymbolRule\n\t\t\t= RhsDefiningSymbolGlobalFunction\n\t\t= RhsDefiningSymbolRule\n\nisDefiningSymbol :: RhsDefiningSymbol Token -> Bool\nisDefiningSymbol (RhsDefiningSymbolExact wanted) observed\n\t=\twanted == observed\nisDefiningSymbol RhsDefiningSymbolCase observed\n\t=\tobserved == EqualToken || observed == ArrowToken\nisDefiningSymbol RhsDefiningSymbolRule observed\n\t=\tobserved == EqualToken || observed == DoubleArrowToken\nisDefiningSymbol RhsDefiningSymbolGlobalFunctionOrMacro observed\n\t=\tobserved == EqualToken || observed == ColonDefinesToken || observed == DefinesColonToken || observed == DoubleArrowToken\nisDefiningSymbol RhsDefiningSymbolRuleOrMacro observed\n\t=\tobserved == EqualToken || observed == ColonDefinesToken || observed == DoubleArrowToken\nisDefiningSymbol RhsDefiningSymbolGlobalFunction observed\n\t=\tobserved == EqualToken || observed == ColonDefinesToken || observed == DefinesColonToken\n\ndefiningSymbolToFunKind :: RhsDefiningSymbol -> FunKind\ndefiningSymbolToFunKind (RhsDefiningSymbolExact defining_token)\n\t=\tdefiningTokenToFunKind defining_token\ndefiningSymbolToFunKind _\n\t=\tFK_Unknown\n\ndefiningTokenToFunKind :: Token -> FunKind\ndefiningTokenToFunKind ColonDefinesToken\n\t=\tFK_Macro\ndefiningTokenToFunKind EqualToken\n\t=\tFK_Function cNameNotLocationDependent\ndefiningTokenToFunKind DoubleArrowToken\n\t=\tFK_Function cNameNotLocationDependent\ndefiningTokenToFunKind DefinesColonToken\n\t=\tFK_Caf\ndefiningTokenToFunKind _\n\t=\tFK_Unknown\n\nwantRhs_without_where :: !Token !Bool !RhsDefiningSymbol !ParseState -> (!Rhs, !RhsDefiningSymbol, !ParseState) \/\/ FunctionAltDefRhs\nwantRhs_without_where token localsExpected definingSymbol pState\n\t# (nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t (alts, definingSymbol, pState) = want_FunctionBody token nodeDefs [] definingSymbol pState\n\t= ({ rhs_alts = alts, rhs_locals = LocalParsedDefs []}, definingSymbol, pState)\nwhere\n\twant_FunctionBody :: !Token ![NodeDefWithLocals] ![GuardedExpr] !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState)\n\twant_FunctionBody BarToken nodeDefs alts definingSymbol pState\n\t\t#\t(file_name, line_nr, pState)= getFileAndLineNr pState\n\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t|\ttoken == OtherwiseToken\n\t\t\t#\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs2, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t= want_FunctionBody token (nodeDefs ++ nodeDefs2) alts definingSymbol pState \/\/ to allow | otherwise | c1 = .. | c2 = ..\n\t\t|\ttoken == LetToken True\n\t\t\t#\tpState\t= parseError \"RHS\" No \"No 'let!' in this version of Clean\" pState\n\t\t\t=\troot_expression token nodeDefs (reverse alts) definingSymbol pState\n\t\t#\t(guard, pState)\t\t\t\t= wantExpressionT token pState\n\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t(nodeDefs2, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t|\ttoken == BarToken \/\/ nested guard\n\t\t\t#\t(position, pState)\t\t\t= getPosition pState\n\t\t\t\toffside\t\t\t\t\t\t= position.fp_col\n\t\t\t\t(expr, definingSymbol, pState)\n\t\t\t\t\t\t\t\t\t\t\t= want_FunctionBody token nodeDefs2 [] definingSymbol pState\n\t\t\t\tpState\t\t\t\t\t\t= wantEndNestedGuard (default_found expr) offside pState\n\t\t\t\talt\t\t\t\t\t\t\t= { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr,\n\t\t\t\t\t\t\t\t\t\t\t\talt_ident = guard_ident line_nr, alt_position = LinePos file_name line_nr }\n\t\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t=\twant_FunctionBody token nodeDefs [alt:alts] definingSymbol pState\n\t\t\/\/ otherwise\n\t\t\t#\t(expr, definingSymbol, pState)\n\t\t\t\t\t\t\t\t\t\t\t= root_expression token nodeDefs2 [] definingSymbol pState\n\t\t\t\talt\t\t\t\t\t\t\t= { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr,\n\t\t\t\t\t\t\t\t\t\t\t\talt_ident = guard_ident line_nr, alt_position = LinePos file_name line_nr }\n\t\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t=\twant_FunctionBody token nodeDefs [alt:alts] definingSymbol pState\n\t where\n\t \tguard_ident line_nr\n\t\t\t= { id_name = \"_g;\" +++ toString line_nr +++ \";\", id_info = nilPtr }\n\twant_FunctionBody token nodeDefs alts definingSymbol pState\n\t\t=\troot_expression token nodeDefs (reverse alts) definingSymbol pState\n\n\troot_expression :: !Token ![NodeDefWithLocals] ![GuardedExpr] !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState)\n\troot_expression token nodeDefs alts definingSymbol pState\n\t\t# (optional_expr,definingSymbol,pState) = want_OptExprWithLocals token nodeDefs definingSymbol pState\n\t\t= build_root token optional_expr alts nodeDefs definingSymbol pState\n\n\twant_OptExprWithLocals :: !Token ![NodeDefWithLocals] !RhsDefiningSymbol !ParseState -> (!Optional ExprWithLocalDefs, !RhsDefiningSymbol, !ParseState)\n\twant_OptExprWithLocals token nodeDefs definingSymbol pState\n\t\t| isDefiningSymbol definingSymbol token\n\t\t# (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t\t (expr, pState)\t= wantExpression pState\n\t\t locals = LocalParsedDefs []\n\t\t= ( Yes\t{ ewl_nodes\t\t= nodeDefs\n\t\t\t\t, ewl_expr\t\t= expr\n\t\t\t\t, ewl_locals\t= locals\n\t\t\t\t, ewl_position\t= LinePos file_name line_nr\n\t\t\t\t}\n\t\t , RhsDefiningSymbolExact token\n\t\t , pState\n\t\t )\n\t\t= (No, definingSymbol, tokenBack pState)\n\nwantRhs :: !Bool !RhsDefiningSymbol !ParseState -> (!Rhs, !RhsDefiningSymbol, !ParseState) \/\/ FunctionAltDefRhs\nwantRhs localsExpected definingSymbol pState\n\t# (alts, definingSymbol, pState)\t= want_LetsFunctionBody definingSymbol pState\n\t (locals, pState)\t= optionalLocals WhereToken localsExpected pState\n\t= ({ rhs_alts = alts, rhs_locals = locals}, definingSymbol, pState)\nwhere\n\twant_LetsFunctionBody :: !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState) \n\twant_LetsFunctionBody definingSymbol pState\n\t\t# (token, pState)\t\t\t= nextToken FunctionContext pState\n\t\t (nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t= want_FunctionBody token nodeDefs [] definingSymbol pState\n\n\twant_FunctionBody :: !Token ![NodeDefWithLocals] ![GuardedExpr] !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState)\n\twant_FunctionBody BarToken nodeDefs alts definingSymbol pState\n\/\/\t\t#\t(lets, pState)\t\t\t\t= want_StrictLet pState \/\/ removed from 2.0\n\t\t#\t(file_name, line_nr, pState)= getFileAndLineNr pState\n\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t|\ttoken == OtherwiseToken\n\t\t\t#\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs2, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t= want_FunctionBody token (nodeDefs ++ nodeDefs2) alts definingSymbol pState \/\/ to allow | otherwise | c1 = .. | c2 = ..\n\t\t|\ttoken == LetToken True\n\t\t\t#\tpState\t= parseError \"RHS\" No \"No 'let!' in this version of Clean\" pState\n\t\t\t=\troot_expression True token nodeDefs (reverse alts) definingSymbol pState\n\t\t#\t(guard, pState)\t\t\t\t= wantExpressionT token pState\n\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t(nodeDefs2, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t|\ttoken == BarToken \/\/ nested guard\n\t\t\t#\t(position, pState)\t\t\t= getPosition pState\n\t\t\t\toffside\t\t\t\t\t\t= position.fp_col\n\t\t\t\t(expr, definingSymbol, pState)\n\t\t\t\t\t\t\t\t\t\t\t= want_FunctionBody token nodeDefs2 [] definingSymbol pState\n\t\t\t\tpState\t\t\t\t\t\t= wantEndNestedGuard (default_found expr) offside pState\n\t\t\t\talt\t\t\t\t\t\t\t= { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr,\n\t\t\t\t\t\t\t\t\t\t\t\talt_ident = guard_ident line_nr, alt_position = LinePos file_name line_nr }\n\t\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t=\twant_FunctionBody token nodeDefs [alt:alts] definingSymbol pState\n\t\t\/\/ otherwise\n\t\t\t#\t(expr, definingSymbol, pState)\n\t\t\t\t\t\t\t\t\t\t\t= root_expression True token nodeDefs2 [] definingSymbol pState\n\t\t\t\talt\t\t\t\t\t\t\t= { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr,\n\t\t\t\t\t\t\t\t\t\t\t\talt_ident = guard_ident line_nr, alt_position = LinePos file_name line_nr }\n\t\t\t\t(token, pState)\t\t\t\t= nextToken FunctionContext pState\n\t\t\t\t(nodeDefs, token, pState)\t= want_LetBefores token localsExpected pState\n\t\t\t=\twant_FunctionBody token nodeDefs [alt:alts] definingSymbol pState\n\t where\n\t \tguard_ident line_nr\n\t\t\t= { id_name = \"_g;\" +++ toString line_nr +++ \";\", id_info = nilPtr }\n\twant_FunctionBody token nodeDefs alts definingSymbol pState\n\t\t=\troot_expression localsExpected token nodeDefs (reverse alts) definingSymbol pState\n\n\troot_expression :: !Bool !Token ![NodeDefWithLocals] ![GuardedExpr] !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState)\n\troot_expression withExpected token nodeDefs alts definingSymbol pState\n\t\t# (optional_expr,definingSymbol,pState) = want_OptExprWithLocals withExpected token nodeDefs definingSymbol pState\n\t\t= build_root token optional_expr alts nodeDefs definingSymbol pState\n\n\twant_OptExprWithLocals :: !Bool !Token ![NodeDefWithLocals] !RhsDefiningSymbol !ParseState -> (!Optional ExprWithLocalDefs, !RhsDefiningSymbol, !ParseState)\n\/\/\twant_OptExprWithLocals withExpected DoubleArrowToken nodeDefs pState\n\/\/\t\t= want_OptExprWithLocals True EqualToken nodeDefs (replaceToken EqualToken pState)\n\twant_OptExprWithLocals withExpected token nodeDefs definingSymbol pState\n\t\t| isDefiningSymbol definingSymbol token\n\t\t# (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t\t (expr, pState)\t= wantExpression pState\n\t\t pState\t\t\t= wantEndRootExpression pState\n\t\t (locals,pState)\t= optionalLocals WithToken withExpected pState\n\t\t= ( Yes\t{ ewl_nodes\t\t= nodeDefs\n\t\t\t\t, ewl_expr\t\t= expr\n\t\t\t\t, ewl_locals\t= locals\n\t\t\t\t, ewl_position\t= LinePos file_name line_nr\n\t\t\t\t}\n\t\t , RhsDefiningSymbolExact token\n\t\t , pState\n\t\t )\n\t\t= (No, definingSymbol, tokenBack pState)\n\nbuild_root :: !Token !(Optional ExprWithLocalDefs) ![GuardedExpr] ![NodeDefWithLocals] !RhsDefiningSymbol !ParseState -> (!OptGuardedAlts, !RhsDefiningSymbol, !ParseState)\nbuild_root _ (Yes expr) [] _ definingSymbol pState\n\t= ( UnGuardedExpr expr, definingSymbol, pState)\nbuild_root _ No alts=:[_:_] [] definingSymbol pState\n\t= (GuardedAlts alts No, definingSymbol, pState)\nbuild_root _ optional_expr alts=:[_:_] _ definingSymbol pState\n\t= (GuardedAlts alts optional_expr, definingSymbol, pState)\nbuild_root token _ _ _ definingSymbol pState\n\t# (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t=\t(UnGuardedExpr {ewl_nodes = [], ewl_expr = PE_Empty, ewl_locals = LocalParsedDefs [],\n\t\t\t\t\t\t\t\t\t\tewl_position = LinePos file_name line_nr}\n\t\t\t\t\t, definingSymbol\n\t\t\t\t\t, parseError \"RHS: root expression\" (Yes token) \"= \" pState\n\t\t\t\t\t)\n\ndefault_found (GuardedAlts _ No)\t= False\ndefault_found _\t\t\t\t\t\t= True\n\n\/*\twant_StrictLet :: !ParseState -> ([NodeDefWithLocals] , !ParseState) \/\/ Removed from the language !?\n\twant_StrictLet pState\n\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t| token == LetToken True\n\t\t\t# (let_defs, pState)\t= wantList \"\" (try_LetDef True) pState\n\t\t\t pState\t\t\t\t= wantToken FunctionContext \"strict let\" InToken pState\n\t\t\t= (let_defs, pState)\n\t\t= ([], tokenBack pState)\n*\/\nwant_LetBefores :: !Token !Bool !ParseState -> (![NodeDefWithLocals], !Token, !ParseState)\nwant_LetBefores (SeqLetToken strict) localsExpected pState\n\t# (let_defs, pState)\t\t\t\t= wantList \"\" (try_LetDef strict) pState\n\t (token, pState)\t\t\t\t\t= nextToken FunctionContext pState\n\t (token, pState)\t\t\t\t\t= opt_End_Group token pState\n\t (more_let_defs, token, pState)\t= want_LetBefores token localsExpected pState\n\t= (let_defs ++ more_let_defs, token, pState)\nwhere\n\topt_End_Group token pState\n\t #\t(ss_useLayout, pState) = accScanState UseLayout pState\n\t |\tss_useLayout\n\t \t| token == EndGroupToken\n\t \t\t= nextToken FunctionContext pState\n\t \t\/\/ otherwise \/\/ token <> EndGroupToken\n\t \t\t= (ErrorToken \"End group missing in let befores\", parseError \"RHS: Let befores\" (Yes token) \"Generated End Group (due to layout)\" pState)\n\t |\totherwise \/\/ not ss_useLayout\n\t =\t(token, pState)\n\n\ttry_LetDef :: !Bool !ParseState -> (!Bool, NodeDefWithLocals, !ParseState)\n\ttry_LetDef strict pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tIdentToken name\n\t\t\t\t| isLowerCaseName name\n\t\t\t\t\t# (id, pState) = stringToIdent name IC_Expression pState\n\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t| token == DefinesColonToken\n\t\t\t\t\t\t# (succ, expr, pState) = trySimplePattern pState\n\t\t\t\t\t\t| succ\n\t\t\t\t\t\t\t# lhs_exp = PE_Bound { bind_dst = id, bind_src = expr }\n\t\t\t\t\t\t\t-> parse_let_rhs lhs_exp pState\n\t\t\t\t\t\t\t# pState = parseError \"simple expression\" No \"expression\" pState\n\t\t\t\t\t\t\t lhs_exp = PE_Empty\n\t\t\t\t\t\t\t-> parse_let_rhs lhs_exp pState\n\n\t\t\t\t\t| token == AndToken\n\t\t\t\t\t\t# lhs_exp = PE_Ident id\n\t\t\t\t\t\t (file_name, line_nr, pState) = getFileAndLineNr pState\n\t\t\t\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t (update_exp, pState) = want_update_without_curly_close NoRecordName lhs_exp token pState\n\t\t\t\t\t\t pState = wantEndRootExpression pState\n\t\t\t\t \t \t (locals , pState) = optionalLocals WithToken localsExpected pState\n\t\t\t\t\t\t ndwl = {\tndwl_strict\t= strict\n\t\t\t\t\t\t\t\t ,\tndwl_def\t= { bind_dst = lhs_exp, bind_src = update_exp }\n\t\t\t\t\t\t\t\t , ndwl_locals\t= locals\n\t\t\t\t\t\t\t\t , ndwl_position\n\t\t\t\t\t\t\t\t \t\t\t\t= LinePos file_name line_nr\n\t\t\t\t\t\t\t }\n\t\t\t\t\t\t->\t(True, ndwl, pState)\n\t\t\t\t\t\n\t\t\t\t\t\t# lhs_exp = PE_Ident id\n\t\t\t\t\t\t pState = tokenBack pState\n\t\t\t\t\t\t-> parse_let_rhs lhs_exp pState\t\t\t\t\t\n\t\t\t_\n\t\t\t\t# (succ, lhs_exp, pState) = trySimplePatternT token pState\n\t\t\t\t| succ\n\t\t\t\t\t-> parse_let_rhs lhs_exp pState\n\t\t\t\t\t-> (False, abort \"no definition\", pState)\n\twhere\n\t\tparse_let_rhs lhs_exp pState\n\t\t\t# pState\t\t\t= wantToken FunctionContext \"let definition\" EqualToken pState\n\t\t\t (file_name, line_nr, pState)\n\t\t\t \t\t\t\t\t= getFileAndLineNr pState\n\t\t\t (rhs_exp, pState) = wantExpression pState\n\t\t\t pState\t\t\t= wantEndRootExpression pState \/\/ -->> (\"#\",lhs_exp,\"=\",rhs_exp)\n\t \t \t (locals , pState) = optionalLocals WithToken localsExpected pState\n\t\t\t=\t( True\n\t\t\t\t, {\tndwl_strict\t= strict\n\t\t\t\t ,\tndwl_def\t= { bind_dst = lhs_exp\n\t\t\t\t \t\t\t\t , bind_src = rhs_exp\n\t\t\t\t \t\t\t\t }\n\t\t\t\t , ndwl_locals\t= locals\n\t\t\t\t , ndwl_position\n\t\t\t\t \t\t\t\t= LinePos file_name line_nr\n\t\t\t\t }\n\t\t\t\t, pState\n\t\t\t\t)\nwant_LetBefores token localsExpected pState\n\t= ([], token, pState)\n\noptionalLocals :: !Token !Bool !ParseState -> (!LocalDefs, !ParseState)\noptionalLocals dem_token localsExpected pState\n # (off_token, pState) = nextToken FunctionContext pState\n\t| dem_token == off_token\n\t\t= wantLocals pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t| off_token == CurlyOpenToken && ~ ss_useLayout && localsExpected\n\t\t= wantLocals (tokenBack pState)\n\t\/\/ otherwise\n\t\t= (LocalParsedDefs [], tokenBack pState)\n\nwantLocals :: !ParseState -> (LocalDefs, !ParseState)\nwantLocals pState\n\t# pState\t\t\t= wantBeginGroup \"local definitions\" pState\n\t (defs, pState)\t= wantDefinitions cLocalContext pState\n\t= (LocalParsedDefs defs, wantEndLocals pState)\n\n\/*\n\timports and exports\n*\/\n\nwantImports :: !ParseState -> (![ParsedImport], !ParseState)\nwantImports pState\n\t# (imports, pState) = wantModuleImports (IC_Module NoQualifiedIdents) pState\n\t pState = wantEndOfDefinition \"imports\" pState\n\t= (imports, pState)\n\nwantModuleImports :: !IdentClass !ParseState -> (![Import], !ParseState)\nwantModuleImports ident_class pState\n\t# (import_qualified, first_name, pState) = wantOptionalQualifiedAndModuleName pState\n\t (first_ident, pState) = stringToIdent first_name ident_class pState\n\t (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t position = LinePos file_name line_nr\n\t (token, pState) = nextToken FunctionContext pState\n\t (import_qualified,token, pState) = parse_optional_as_module_name import_qualified token pState\n\t module_import = {import_module = first_ident, import_symbols = ImportSymbolsAll, import_file_position = position, import_qualified = import_qualified}\n\t| token == CommaToken\n\t\t# (rest, pState) = wantModuleImports ident_class pState\n\t\t= ([module_import : rest], pState)\n\t= ([module_import], tokenBack pState)\nwhere\n\tparse_optional_as_module_name import_qualified=:Qualified token=:(IdentToken \"as\") pState\n\t\t# (mod_name, pState) = wantModuleName pState\n\t\t (mod_ident, pState) = stringToIdent mod_name (IC_Module NoQualifiedIdents) pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t= (QualifiedAs mod_ident,token,pState)\n\tparse_optional_as_module_name import_qualified token pState\n\t\t= (import_qualified,token,pState)\n\nwantFromImports :: !ParseState -> (!ParsedImport, !ParseState)\nwantFromImports pState\n\t# (mod_name, pState) = wantModuleName pState\n\t (mod_ident, pState) = stringToIdent mod_name (IC_Module NoQualifiedIdents) pState\n\t (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tImportToken\n\t\t\t-> wantOptionalQualifiedAndImportDeclarations mod_ident pState\n\t\tIdentToken \"as\"\n\t\t\t# (as_mod_name, pState) = wantModuleName pState\n\t\t\t (as_mod_ident, pState) = stringToIdent as_mod_name (IC_Module NoQualifiedIdents) pState\n\t\t\t pState = wantToken GeneralContext \"from imports\" ImportToken pState\n\t\t\t pState = wantToken GeneralContext \"from imports\" (IdentToken \"qualified\") pState\t\t\t\t\n\t\t\t (file_name, line_nr, pState) = getFileAndLineNr pState\n\t\t\t (import_symbols, pState) = wantImportDeclarations pState\n\t\t\t pState = wantEndOfDefinition \"from imports\" pState\n\t\t\t-> ({import_module = mod_ident, import_symbols = ImportSymbolsOnly import_symbols,\n\t\t\t\t import_file_position = LinePos file_name line_nr, import_qualified = QualifiedAs as_mod_ident}, pState)\n\t\t_\n\t\t\t# pState = parseError \"from imports\" (Yes token) \"import or as\" pState\n\t\t\t-> wantOptionalQualifiedAndImportDeclarations mod_ident pState\n\twhere\n\twantOptionalQualifiedAndImportDeclarations mod_ident pState\n\t\t# (file_name, line_nr, pState)\t= getFileAndLineNr pState\n\t\t (token, pState) = nextToken GeneralContext pState\n\t\t| case token of IdentToken \"qualified\" -> True ; _ -> False\n\t\t\t# (import_symbols, pState) = wantImportDeclarations pState\n\t\t\t pState = wantEndOfDefinition \"from imports\" pState\n\t\t\t= ( { import_module = mod_ident, import_symbols = ImportSymbolsOnly import_symbols,\n\t\t\t\t import_file_position = LinePos file_name line_nr, import_qualified = Qualified }, pState)\n\t\t# (import_symbols, pState) = wantImportDeclarationsT token pState\n\t\t pState = wantEndOfDefinition \"from imports\" pState\n\t\t= ( { import_module = mod_ident, import_symbols = ImportSymbolsOnly import_symbols,\n\t\t\t import_file_position = LinePos file_name line_nr, import_qualified = NotQualified }, pState)\n\n\twantImportDeclarations pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t= wantImportDeclarationsT token pState\n\n\twantImportDeclarationsT token pState\n\t\t# (first, pState) = wantImportDeclarationT token pState\n\t\t (token, pState) = nextToken GeneralContext pState\n\t\t| token == CommaToken\n\t\t\t# (rest, pState) = wantImportDeclarations pState\n\t\t\t= ([first : rest], pState)\n\t\t\t= ([first], tokenBack pState)\n\ninstance want ImportedObject where\n\twant pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t| token == IdentToken \"library\"\n\t \t\t# (token, pState) = nextToken GeneralContext pState\n\t\t\t= want_import_string token cIsImportedLibrary pState\n\t\t\t= want_import_string token cIsImportedObject pState\n\t\twhere\t\t\n\t\t\twant_import_string :: Token Bool ParseState -> (ImportedObject, ParseState)\n\t\t\twant_import_string (StringToken string) isLibrary pState\n\t\t\t\t=\t({io_is_library = isLibrary, io_name = string}, pState)\n\t\t\twant_import_string token isLibrary pState\n\t\t\t\t=\t({io_is_library = isLibrary, io_name = \"\"}, parseError \"import code declaration\" (Yes token) \"imported item\" pState)\n\nwantCodeImports :: !ParseState -> (![ImportedObject], !ParseState)\nwantCodeImports pState\n\t# pState = wantToken GeneralContext \"import code declaration\" FromToken pState\n\t (importObjects, pState) = wantSequence CommaToken GeneralContext pState\n\t= (importObjects, wantEndOfDefinition \"import code declaration\" pState)\n\ninstance want ImportDeclaration\nwhere\n\twant pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t= wantImportDeclarationT token pState\n\nwantImportDeclarationT token pState\n\t= case token of\n\t\tDoubleColonToken\n\t\t\t# (name, pState)\t\t\t\t= wantConstructorName \"import type\" pState\n\t\t\t (type_id, pState)\t\t\t\t= stringToIdent name IC_Type pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == OpenToken\n\t\t\t \t#\t(conses, pState)\t\t\t= want_names (wantConstructorName \"import type (..)\") IC_Expression CloseToken pState\n\t\t\t \t->\t(ID_Type type_id (Yes conses), pState)\n\t\t\t| token == CurlyOpenToken\n\t\t\t \t#\t(fields, pState) = want_names (wantLowerCaseName \"import record fields\") (IC_Field type_id) CurlyCloseToken pState\n\t\t\t \t->\t(ID_Record type_id (Yes fields), pState)\n\t\t\t \t->\t(ID_Type type_id No, tokenBack pState)\n\t\tClassToken\n\t\t\t# (name, pState)\t\t\t\t= want pState\n\t\t\t (class_id, pState)\t\t\t= stringToIdent name IC_Class pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == OpenToken\n\t\t\t \t#\t(members, pState)\t\t\t= want_names want IC_Expression CloseToken pState\n\t\t\t \t->\t(ID_Class class_id (Yes members), pState)\n\t\t\t \t->\t(ID_Class class_id No, tokenBack pState)\n\t\tInstanceToken\n\t\t\t#\t(class_name, pState)\t= want pState\n\t\t\t\t(types, pState)\t\t\t= wantList \"instance types\" tryBrackType pState\n\t\t\t\t(class_id, pState)\t\t= stringToIdent class_name IC_Class pState\n\t\t\t\t(inst_id, pState)\t\t= stringToIdent class_name (IC_Instance types) pState\n\t\t\t\t(context, pState)\t\t= optionalContext pState\n\t\t\t->\t(ID_Instance class_id inst_id (types,context), pState)\n\t\tIdentToken fun_name\n\t\t\t#\t(fun_id, pState)\t\t= stringToIdent fun_name IC_Expression pState\n\t\t\t\t(ii_extended, pState)\t= optional_extension pState\n\t\t\t->\t(ID_Function fun_id, pState)\n\t\tGenericToken\n\t\t\t#\t(name, pState)\t\t\t= want pState\n\t\t\t\t(generic_id, pState)\t= stringToIdent name IC_Generic pState\n\t\t\t\t(expr_id, pState)\t\t= stringToIdent name IC_Expression pState\n\t\t \t->\t(ID_Generic generic_id expr_id, pState)\n\t\ttoken\n\t\t\t#\t(fun_id, pState)\t\t= stringToIdent \"dummy\" IC_Expression pState\n\t\t\t->\t( ID_Function fun_id\n\t\t\t\t, parseError \"from import\" (Yes token) \"imported item\" pState\n\t\t\t\t)\nwhere\t\t\t\t\n\twant_names want_fun ident_kind close_token pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == DotDotToken\n\t\t\t= ([], wantToken FunctionContext \"import declaration\" close_token pState)\n\t\t\t= want_list_of_names want_fun ident_kind close_token (tokenBack pState)\n\n\twant_list_of_names want_fun ident_kind close_token pState\n\t\t# (name, pState) = want_fun pState\n\t\t (name_id, pState)\t= stringToIdent name ident_kind pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (names, pState) = want_list_of_names want_fun ident_kind close_token pState\n\t\t\t= ([name_id : names], pState)\n\t\t| token == close_token\n\t\t\t= ([name_id], pState)\n\t\t\t= ([name_id], parseError \"ImportDeclaration\" (Yes token) \")\" pState)\n\t\t\n\toptional_extension pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == DotDotToken\n\t\t\t= (True, pState)\n\t\t\t= (False, tokenBack pState)\t\t\t\n\n\/*\n\tClasses and instances\n*\/\n\ncIsAGlobalContext\t\t:== True\ncIsNotAGlobalContext\t:== False\n\ncMightBeAClass\t\t\t:== True\ncIsNotAClass\t\t\t:== False\n\n\t\t\nwantClassDefinition :: !ParseContext !Position !ParseState -> (!ParsedDefinition, !ParseState)\nwantClassDefinition parseContext pos pState\n\t# (might_be_a_class, class_or_member_name, prio, pState) = want_class_or_member_name pState\n\t (class_variables, pState) = wantList \"class variable(s)\" try_class_variable pState\n\t (class_arity, class_args, class_fun_dep_vars, class_cons_vars) = convert_class_variables class_variables 0 0 0\n\t (contexts, pState) = optionalContext pState\n \t (token, pState) = nextToken TypeContext pState\n \t| token == DoubleColonToken\n\t\t= want_overloaded_function pos class_or_member_name prio class_arity class_args class_fun_dep_vars class_cons_vars contexts pState\n\t| might_be_a_class\n\t\t# (begin_members, pState) = begin_member_group token pState\n\t\t| begin_members\n\t\t\t# (class_id, pState) = stringToIdent class_or_member_name IC_Class pState\n\t\t \t (members, pState) = wantDefinitions (SetClassDefsContext parseContext) pState\n \t\t \t class_def = { class_ident = class_id, class_arity = class_arity, class_args = class_args,\n\t \t\t\t\t\tclass_context = contexts, class_pos = pos, class_members = {}, class_cons_vars = class_cons_vars,\n\t \t\t\t\t\tclass_fun_dep_vars = class_fun_dep_vars, class_lazy_members = 0,\n\t \t\t\t\t\tclass_dictionary = { ds_ident = { class_id & id_info = nilPtr }, ds_arity = 0, ds_index = NoIndex}\n\t\t\t\t\t\t }\n\t \t pState = wantEndGroup \"class\" pState\n\t\t\t= (PD_Class class_def members, pState)\n\t\t| isEmpty contexts\n\t\t\t= (PD_Erroneous, parseError \"Class Definition\" (Yes token) \": contexts\" pState)\n\t\t\/\/ otherwise\n\t\t\t# pState = tokenBack pState\n\t\t\t (class_id, pState) = stringToIdent class_or_member_name IC_Class pState\n \t\t\t class_def = { class_ident = class_id, class_arity = class_arity, class_args = class_args,\n\t\t\t\t\t\t\tclass_context = contexts, class_pos = pos, class_members = {}, class_cons_vars = class_cons_vars,\n\t\t\t\t\t\t\tclass_fun_dep_vars = class_fun_dep_vars, class_lazy_members = 0,\n\t\t\t\t\t\t\tclass_dictionary = { ds_ident = { class_id & id_info = nilPtr }, ds_arity = 0, ds_index = NoIndex }\n\t\t\t\t\t\t }\n\t \t\t pState = wantEndOfDefinition \"class definition\" pState\n\t\t\t= (PD_Class class_def [], pState)\n\t\t= (PD_Erroneous, parseError \"Class Definition\" (Yes token) \"\" pState)\n\twhere\n\t\tbegin_member_group token pState \/\/ For JvG layout\n\t\t\t# (token, pState)\n\t\t\t\t= case token of\n\t\t\t\t\tSemicolonToken\t->\tnextToken TypeContext pState\n\t\t\t\t\t_\t\t\t\t->\t(token, pState)\n\t\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t\t| token == WhereToken\n\t\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t\t| token == CurlyOpenToken\n\t\t\t\t\t| ss_useLayout\n\t\t\t\t\t\t= (True, parseError \"class definition\" No \"No { in layout mode\" pState) \n\t\t\t\t\t\t= (True, pState)\n\t\t\t\t\t= (True, tokenBack pState)\n\t\t\t| token == CurlyOpenToken \n\t\t\t\t| ss_useLayout\n\t\t\t\t\t= (True, parseError \"class definition\" (Yes CurlyOpenToken) \"in layout mode the keyword where is\" pState) \n\t\t\t\t\t= (True, pState)\n\t\t\t\t= (False, pState) \/\/ token is still known: no tokenBack\n\t\t\n\t\twant_class_or_member_name pState \n\/\/ PK\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t\t| token == OpenToken\n\t\t\t\t# (member_name, pState) = want pState\n\t\t\t\t pState = wantToken GeneralContext \"class definition\" CloseToken pState\n\t\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t\t (prio, pState) = optionalPriority cIsInfix token pState \n\t\t\t\t= (cIsNotAClass, member_name, prio, pState)\n \t\t\t\t# (class_ident, pState) = want_name token pState\n\t\t\t\t= (cMightBeAClass, class_ident, NoPrio, pState)\n\t\twhere\n\t\t\twant_name (IdentToken name) pState\n\t\t\t\t= (name, pState)\n\t\t\twant_name token pState\n\t\t\t\t= (\"\", parseError \"Class Definition\" (Yes token) \"\" pState)\n\n\t\twant_overloaded_function pos member_name prio class_arity class_args class_fun_dep_vars class_cons_vars contexts pState\n\t\t\t# (tspec, pState) = wantSymbolType pState\n\t\t\t (member_id, pState) = stringToIdent member_name IC_Expression pState\n\t\t\t (class_id, pState) = stringToIdent member_name IC_Class pState\n\t\t\t member = PD_TypeSpec pos member_id prio (Yes tspec) FSP_None\n\t\t\t class_def = {\tclass_ident = class_id, class_arity = class_arity, class_args = class_args,\n\t\t \t\t\t\tclass_context = contexts, class_pos = pos, class_members = {}, class_cons_vars = class_cons_vars,\n\t\t \t\t\t\tclass_fun_dep_vars = class_fun_dep_vars, class_lazy_members = 0,\n \t\t\t\t\t\t\tclass_dictionary = { ds_ident = { class_id & id_info = nilPtr }, ds_arity = 0, ds_index = NoIndex }\n \t\t\t\t\t\t }\n\t \t\t pState = wantEndOfDefinition \"overloaded function\" pState\n\t\t\t= (PD_Class class_def [member], pState)\n\n\t\ttry_class_variable pState\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= case token of\n\t\t\t\tIdentToken \"~\"\n\t\t\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t\t\t-> case token of\n\t\t\t\t\t\tDotToken\n\t\t\t\t\t\t\t# (type_var, pState) = wantTypeVar pState\n\t\t\t\t\t\t\t= (True, (1, 1, type_var), pState)\n\t\t\t\t\t\t_\n\t\t\t\t\t\t\t# (type_var, pState) = wantTypeVarT token pState\n\t\t\t\t\t\t\t= (True, (1, 0, type_var), pState)\n\t\t\t\tDotToken\n\t\t\t\t\t# (type_var, pState) = wantTypeVar pState\n\t\t\t\t\t-> (True, (0, 1, type_var), pState)\n\t\t\t\t_\n\t\t\t\t\t# (succ, type_var, pState) = tryTypeVarT token pState\n\t\t\t\t\t-> (succ, (0, 0, type_var), pState)\n\n\t\tconvert_class_variables [(fun_dep_var, annot, var) : class_vars] arg_nr fun_dep_vars cons_vars\n\t\t\t# (arity, class_vars, fun_dep_vars, cons_vars)\n\t\t\t\t= convert_class_variables class_vars (arg_nr+1) fun_dep_vars cons_vars\n\t\t\t#! fun_dep_vars = (fun_dep_vars<<1) bitor fun_dep_var\n\t\t\t cons_vars = (cons_vars<<1) bitor annot\n\t\t\t= (arity, [var : class_vars], fun_dep_vars, cons_vars)\n\t\tconvert_class_variables [] arg_nr fun_dep_vars cons_vars\n\t\t\t= (arg_nr, [], fun_dep_vars, cons_vars)\n\nwantInstanceDeclaration :: !ParseContext !Position !ParseState -> (!ParsedDefinition, !ParseState)\nwantInstanceDeclaration parseContext pi_pos pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tIdentToken class_name\n\t\t\t# (pi_class, pState) = stringToIdent class_name IC_Class pState\n\t\t\t-> want_instance_declaration class_name (Ident pi_class) parseContext pi_pos pState\n\t\tQualifiedIdentToken module_name class_name\n\t\t\t# (module_ident, pState) = stringToQualifiedModuleIdent module_name class_name IC_Class pState\n\t\t\t-> want_instance_declaration class_name (QualifiedIdent module_ident class_name) parseContext pi_pos pState\n\t\t_\n\t\t\t# pState = parseError \"String\" (Yes token) \"identifier\" pState\n\t\t\t# (pi_class, pState) = stringToIdent \"\" IC_Class pState\n\t\t\t-> want_instance_declaration \"\" (Ident pi_class) parseContext pi_pos pState\n\twhere\n\twant_instance_declaration class_name pi_class parseContext pi_pos pState\n\t\t# ((pi_types, pi_context), pState) = want_instance_type pState\n\t\t (pi_ident, pState) = stringToIdent class_name (IC_Instance pi_types) pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| isIclContext parseContext\n\t\t\t# pState = want_begin_group token pState\n\t\t\t (pi_members, pState) = wantDefinitions (SetInstanceDefsContext parseContext) pState\n\t\t\t pState = wantEndGroup \"instance\" pState\n\t\t\t= (PD_Instance {pim_pi = {pi_class = pi_class, pi_ident = pi_ident, pi_types = pi_types, pi_context = pi_context,\n\t\t\t\t\t\t\t\t\t pi_specials = SP_None, pi_pos = pi_pos},\n\t\t\t\t\t\t\tpim_members = pi_members}, pState)\n\t\t\/\/ otherwise \/\/ ~ (isIclContext parseContext)\n\t\t\t| token == CommaToken\n\t\t\t\t# (pi_types_and_contexts, pState)\t= want_instance_types pState\n\t\t\t\t (idents, pState)\t\t= seqList [stringToIdent class_name (IC_Instance type) \\\\ (type,context) <- pi_types_and_contexts] pState\n\t\t\t\t= (PD_Instances\n\t\t\t\t\t[ {\tpim_pi = { pi_class = pi_class, pi_ident = ident, pi_types = type, pi_context = context\n\t\t\t\t\t\t\t\t , pi_specials = SP_None, pi_pos = pi_pos},\n\t\t\t\t\t\tpim_members = [] } \n\t\t\t\t\t\\\\\t(type,context)\t<- [ (pi_types, pi_context) : pi_types_and_contexts ]\n\t\t\t\t\t&\tident\t\t\t<- [ pi_ident : idents ]\n\t\t\t\t\t]\n\t\t\t\t , pState\n\t\t\t\t )\n\t\t\t\/\/ otherwise \/\/ token <> CommaToken\n\t\t\t\t# (specials, pState) = optionalSpecials (tokenBack pState)\n\t\t\t\t# pim_pi = {pi_class = pi_class, pi_ident = pi_ident, pi_types = pi_types,\n\t\t\t\t\t\t\tpi_context = pi_context, pi_specials = specials, pi_pos = pi_pos}\n\t\t\t\t= want_optional_member_types pim_pi pState\n\n\twant_begin_group token pState \/\/ For JvG layout\n\t\t# \/\/ (token, pState) = nextToken TypeContext pState PK\n\t\t (token, pState)\n\t\t\t= case token of\n\t\t\t\tSemicolonToken\t->\tnextToken TypeContext pState\n\t\t\t\t_\t\t\t\t->\t(token, pState)\n\t\t= case token of\n\t\t\tWhereToken\t-> wantBeginGroup \"instance declaration\" pState\n\t\t\tCurlyOpenToken\n\t\t\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t\t\t| ss_useLayout\n\t\t\t\t\t-> parseError \"instance declaration\" (Yes token) \"where\" pState\n\t\t\t\t\t-> pState\n\t\t\t_\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t\t\t| ss_useLayout\n\t\t\t\t\t-> parseError \"instance declaration\" (Yes token) \"where\" pState\n\t\t\t\t\t-> parseError \"instance declaration\" (Yes token) \"where or {\" pState\n\n\twant_optional_member_types pim_pi pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t# (begin_members, pState) = begin_member_group token pState\n\t\t| begin_members\n\t\t\t# (instance_member_types, pState) = want_instance_type_definitions pim_pi.pi_types pState\n \t \t pState = wantEndGroup \"instance\" pState\n\t\t\t= (PD_Instance {pim_pi = pim_pi, pim_members = instance_member_types}, pState)\n\t\t\t# pState = wantEndOfDefinition \"instance declaration\" (tokenBack pState)\n\t\t\t= (PD_Instance {pim_pi = pim_pi, pim_members = []}, pState)\n\n\twant_instance_type pState\n\t\t# (pi_types, pState)\t= wantList \"instance types\" tryBrackType pState\n\t\t (pi_context, pState)\t= optionalContext pState\n\t\t= ((pi_types, pi_context), pState)\n\twant_instance_types pState\n\t\t# (type_and_context, pState) = want_instance_type pState\n\t\t (token, pState) = nextToken TypeContext pState\n\t\t| token == CommaToken\n\t\t\t# (types, pState) = want_instance_types pState\n\t\t\t= ([type_and_context:types], pState)\n\t\t\/\/ otherwise \/\/ token <> CommaToken\n\t\t\t= ([type_and_context], pState)\n\n\tbegin_member_group SemicolonToken pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == WhereToken\n\t\t\t= begin_member_group_where pState\n\t\t| token == CurlyOpenToken\n\t\t\t= begin_member_group_curly_open pState\n\t\t\t= (False, tokenBack pState)\n\tbegin_member_group token pState\n\t\t| token == WhereToken\n\t\t\t= begin_member_group_where pState\n\t\t| token == CurlyOpenToken\n\t\t\t= begin_member_group_curly_open pState\n\t\t\t= (False, pState)\n\n\tbegin_member_group_where pState\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == CurlyOpenToken\n\t\t\t| ss_useLayout\n\t\t\t\t= (True, parseError \"instance definition\" No \"No { in layout mode\" pState) \n\t\t\t\t= (True, pState)\n\t\t\t= (True, tokenBack pState)\n\n\tbegin_member_group_curly_open pState\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t| ss_useLayout\n\t\t\t= (True, parseError \"instance definition\" (Yes CurlyOpenToken) \"in layout mode the keyword where is\" pState) \n\t\t\t= (True, pState)\n\noptionalContext :: !ParseState -> ([TypeContext],ParseState)\noptionalContext pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == BarToken\n\t\t= want_contexts pState\n\t\t= ([], tokenBack pState)\n\noptional_constructor_context :: !ParseState -> ([TypeContext],ParseState)\noptional_constructor_context pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == AndToken\n\t\t= want_contexts pState\n\t\t= ([], tokenBack pState)\n\nwant_contexts :: ParseState -> ([TypeContext],ParseState)\nwant_contexts pState\n\t# (contexts, pState) = want_context pState\n\t (token, pState) = nextToken TypeContext pState\n\t| token == AndToken\n\t\t# (more_contexts, pState) = want_contexts pState\n\t\t= (contexts ++ more_contexts, pState)\n\t\t= (contexts, tokenBack pState)\nwhere\n\/*\t\t\t\n\twant_context pState\n\t\t# (class_names, pState) = wantSequence CommaToken TypeContext pState\n\t\t (types, pState)\t= wantList \"type arguments\" tryBrackType pState \/\/ tryBrackAType ??\n\t\t= build_contexts class_names types (length types) pState\n\twhere\n\t\tbuild_contexts [] types arity pState\n\t\t\t= ([], pState)\n\t\tbuild_contexts [class_ident : class_names] types arity pState\n\t\t\t# (contexts, pState) = build_contexts class_names types arity pState\n\t\t\t (class_ident, pState) = stringToIdent class_ident IC_Class pState\n\t\t\t tc_class = { glob_object = MakeDefinedSymbol class_ident NoIndex (length types), glob_module = NoIndex }\n\t\t\t= ([{ tc_class = tc_class, tc_types = types, tc_var = nilPtr } : contexts], pState)\n*\/\n\/**\/\n\twant_context pState \n\t\t# (tc_classes, pState) = wantSepList \"classes\" CommaToken TypeContext try_tc_class pState\n\t\t# (types, pState)\t= wantList \"type arguments\" tryBrackType pState \/\/ tryBrackAType ??\n\t\t# {ps_error} = pState\n\t\t#! ok = ps_error.pea_ok\n\t\t# pState = {pState & ps_error = ps_error}\n\t\t| ok\n\t\t\t= mapSt (build_context types (length types)) tc_classes pState\n\t\t\t= ([], pState)\n\t\n\ttry_tc_class pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t= case token of \n\t\t\tIdentToken name \n\t\t\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t\t\t-> case token of\n\t\t\t\t\tGenericOpenToken \n\t\t\t\t\t\t# (ident, pState) = stringToIdent name IC_Generic pState\t\t\t\n\t\t\t\t\t\t# (kind, pState) = wantKind pState\t\t\t\t\t\t \n\t\t\t \t\t\t# generic_global_ds = { glob_object = MakeDefinedSymbol ident NoIndex 1, glob_module = NoIndex }\n\t\t\t\t\t\t# class_global_ds = { glob_object = MakeDefinedSymbol {id_name=\"\",id_info=nilPtr} NoIndex 1, glob_module = NoIndex}\n\t\t\t\t\t\t\n\t\t\t\t\t\t# gen_type_context = \n\t\t\t\t\t\t\t{ gtc_generic = {glob_object = MakeDefinedSymbol ident NoIndex 1, glob_module = NoIndex}\n\t\t\t\t\t\t\t, gtc_kind = kind\n\t\t\t\t\t\t\t, gtc_class = {glob_object = MakeDefinedSymbol {id_name=\"\",id_info=nilPtr} NoIndex 1, glob_module = NoIndex}\n\t\t\t\t\t\t\t, gtc_generic_dict = {gi_module = NoIndex, gi_index = NoIndex}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t-> (True, TCGeneric gen_type_context, pState)\n\t\t\t\t\t_ \n\t\t\t\t\t\t# pState = tokenBack pState\n\t\t\t\t\t\t# (ident, pState) = stringToIdent name IC_Class pState\n\t\t\t \t\t\t# class_global_ds = { glob_object = MakeDefinedSymbol ident NoIndex (-1), glob_module = NoIndex }\n\t\t\t\t\t\t-> (True, TCClass class_global_ds, pState)\n\t\t\tQualifiedIdentToken module_name ident_name\n\t\t\t\t# (module_ident, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Class pState\n\t\t\t\t-> (True, TCQualifiedIdent module_ident ident_name, pState)\n\t\t\t_\n\t\t\t\t-> (False, abort \"no tc_class\", tokenBack pState)\n\t\n\tbuild_context types length_types (TCClass class_global_ds=:{glob_object}) pState\n\t\t# tc_class = TCClass {class_global_ds & glob_object = {glob_object & ds_arity = length_types}}\n\t\t= ({ tc_class = tc_class, tc_var = nilPtr, tc_types = types}, pState)\n\tbuild_context types length_types tc_class=:(TCQualifiedIdent module_name ident_name) pState\n\t\t= ({ tc_class = tc_class, tc_var = nilPtr, tc_types = types}, pState)\n\tbuild_context types 1 (TCGeneric gtc=:{gtc_generic=gtc_generic=:{glob_object}}) pState\n\t\t# gtc = { gtc & gtc_generic = {gtc_generic & glob_object = {glob_object & ds_arity = 1}}} \n\t\t= ({ tc_class = TCGeneric gtc, tc_var = nilPtr, tc_types = types }, pState)\n\tbuild_context types length_types tc_class=:(TCGeneric _) pState\n\t\t# pState = parseErrorSimple \"type context\" \"generic class can have only one class argument\" pState\t\t\t\t\t\n\t\t= (abort \"No TypeContext\", pState)\n\/**\/\t\t\t\t\t\t \noptionalCoercions :: !ParseState -> ([AttrInequality], ParseState)\noptionalCoercions pState \n\t# (token, pState) = nextToken TypeContext pState\n\t| token == CommaToken\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == SquareOpenToken\n\t\t\t# (inequals, pState) = want_inequalities pState\n\t\t\t= (inequals, wantToken FunctionContext \"coercions\" SquareCloseToken pState)\n\t\t\t= ([], parseError \"Function type: coersions\" (Yes token) \"[\" pState)\n\t\t= ([], tokenBack pState)\n\twhere\n\t\twant_inequalities pState\n\t\t\t# (token, pState) = nextToken TypeContext pState\n \t\t\t (_, inequals, pState) = want_attr_inequality token pState\n\t\t\t (token, pState) = nextToken TypeContext pState\n\t\t\t| token == CommaToken\n\t\t\t\t# (more_inequals, pState) = want_inequalities pState\n\t\t\t\t= (inequals ++ more_inequals, pState)\n\t\t\t\t= (inequals, tokenBack pState)\n\t\twant_attr_inequality (IdentToken var_name) pState\n\t\t\t| isLowerCaseName var_name\n\t\t\t\t# (off_ident, pState) = stringToIdent var_name IC_TypeAttr pState\n\t\t\t\t (token, pState) = nextToken TypeContext pState\n\t\t\t\t| token == LessThanOrEqualToken\n\t\t\t\t\t# (var_name, pState) = wantLowerCaseName \"attribute inequality\" pState\n\t\t\t\t\t (dem_ident, pState) = stringToIdent var_name IC_TypeAttr pState\n\t\t\t\t\t ai_demanded = makeAttributeVar dem_ident\n\t\t\t\t\t= (ai_demanded, [{ ai_demanded = ai_demanded, ai_offered = makeAttributeVar off_ident }], pState)\t\t\t\t\n\t\t\t\t\t# (ai_demanded, inequals, pState) = want_attr_inequality token pState\n\t\t\t\t\t= (ai_demanded, [{ ai_demanded = ai_demanded, ai_offered = makeAttributeVar off_ident } : inequals], pState)\n\t\twant_attr_inequality token pState\n\t\t\t# erroneous_attr_var = makeAttributeVar erroneousIdent\n\t\t\t= (\terroneous_attr_var\n\t\t\t , [{ ai_demanded = erroneous_attr_var, ai_offered = erroneous_attr_var }]\n\t\t\t , parseError \"Function type: optional coercions\" (Yes token) \"\" pState\n\t\t\t )\n\n\/* Generic definitions *\/\n\nwantGenericDefinition :: !ParseContext !Position !ParseState -> (!ParsedDefinition, !ParseState)\nwantGenericDefinition parseContext pos pState\n\t| pState.ps_flags bitand PS_SupportGenericsMask==0\n\t\t= (PD_Erroneous, parseErrorSimple \"generic definition\" \"to enable generics use the command line flag -generics\" pState)\n\t# (name, pState) = want_name pState\n\t| name == \"\" \n\t\t= (PD_Erroneous, pState)\n\t# (ident, pState) = stringToIdent name IC_Generic\/*IC_Class*\/ pState\n\t# (member_ident, pState) = stringToIdent name IC_Expression pState\n\t# (arg_vars, pState) = wantList \"generic variable(s)\" try_variable pState\n\t# (gen_deps, pState) = optionalDependencies pState\n\t# pState = wantToken TypeContext \"generic definition\" DoubleColonToken pState\n\t# (type, pState) = wantSymbolType pState\n\t# pState = wantEndOfDefinition \"generic definition\" pState\n\t# gen_def = \n\t\t{\tgen_ident = ident\n\t\t,\tgen_member_ident = member_ident \n\t\t,\tgen_type = type\n\t\t,\tgen_vars = arg_vars\n\t\t,\tgen_deps = gen_deps \n\t\t,\tgen_pos = pos\n\t\t,\tgen_info_ptr = nilPtr\n\t\t}\n\t= (PD_Generic gen_def, pState)\t\n\twhere\n\t\twant_name pState \n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= \tcase token of\n\t\t\t\tIdentToken name -> (name, pState)\n\t\t\t\t_ -> (\"\", parseError \"generic definition\" (Yes token) \"\" pState)\n\n\t\ttry_variable pState\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= tryTypeVarT token pState\n\n\t\toptionalDependencies :: !ParseState -> (![GenericDependency], !ParseState)\n\t\toptionalDependencies pState\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= case token of \n\t\t\t\tBarToken -> wantSepList \"generic dependencies\" CommaToken TypeContext wantDependency pState\n\t\t\t\t_ -> ([], tokenBack pState)\n\n\t\twantDependency :: !ParseState -> (Bool, GenericDependency, ParseState)\n\t\twantDependency pState \n\t\t\t# (ident, pState) = wantIdentOrQualifiedIdent pState\n\t\t\t# (vars, pState) = wantList \"generic dependency variable(s)\" try_variable pState\n\t\t\t= (True, {gd_ident = ident, gd_index = NoGlobalIndex, gd_vars = vars, gd_nums = repeatn (length vars) (-1)}, pState)\n\t\t\n\t\twantIdentOrQualifiedIdent pState\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= case token of\n\t\t\t\tIdentToken name \n\t\t\t\t\t# (ident, pState) = stringToIdent name IC_Generic pState\n\t\t\t\t\t= (Ident ident, pState)\n\t\t\t\tQualifiedIdentToken mod_name name \n\t\t\t\t\t# (mod_ident, pState) = stringToQualifiedModuleIdent mod_name name IC_Generic pState\n\t\t\t\t\t= (QualifiedIdent mod_ident name, pState)\n\t\t\t\t_ \n\t\t\t\t\t# (ident, pState) = stringToIdent \"\" IC_Generic pState\n\t\t\t\t\t= (Ident ident, parseError \"generic dependency\" (Yes token) \"\" pState)\n\nwantDeriveDefinition :: !ParseContext !Position !*ParseState -> (!ParsedDefinition, !*ParseState)\nwantDeriveDefinition parseContext pos pState\n\t| pState.ps_flags bitand PS_SupportGenericsMask==0\n\t\t= (PD_Erroneous, parseErrorSimple \"generic definition\" \"to enable generics use the command line flag -generics\" pState)\n\t# (token, pState) = nextToken TypeContext pState\n\t= case token of\n\t\tIdentToken name\n\t\t\t# (derive_defs, pState) = want_derive_types name pState\n\t\t\t-> (PD_Derive derive_defs, pState)\n\t\tClassToken\n\t\t\t# (class_name, pState) = want pState\n\t\t\t# (class_ident, pState) = stringToIdent class_name IC_Class pState\n\t\t\t# (derive_defs, pState) = want_derive_class_types class_ident pState\n\t\t\t-> (PD_Derive derive_defs, pState)\n\t\t_\n\t\t\t-> (PD_Erroneous, parseError \"Generic Definition\" (Yes token) \"\" pState)\nwhere\n\twant_name pState \n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t= \tcase token of\n\t\t\tIdentToken name -> (name, pState)\n\t\t\t_ -> (\"\", parseError \"Generic Definition\" (Yes token) \"\" pState)\n\n\twant_derive_types :: String !*ParseState -> ([GenericCaseDef], !*ParseState)\t\t\t\n\twant_derive_types name pState\n\t\t# (derive_def, token, pState) = want_derive_type name pState\n\t\t| token == CommaToken\n\t\t\t# (derive_defs, pState) = want_derive_types name pState\n\t\t\t= ([derive_def:derive_defs], pState)\n \t\t\t# pState = wantEndOfDefinition \"derive definition\" (tokenBack pState)\n\t\t\t= ([derive_def], pState)\n\n\twant_derive_type :: String !*ParseState -> (GenericCaseDef, !Token, !*ParseState)\t\t\t\n\twant_derive_type name pState\n\/\/\t\t# (type, pState) = wantType pState\n\t\t# (ok, {at_type=type}, pState) = trySimpleType TA_None pState\n\t\t# (ident, pState) = stringToIdent name (IC_GenericCase type) pState\n\t\t# (generic_ident, pState) = stringToIdent name IC_Generic pState\n\t\t# (type_cons, pState) = get_type_cons type pState\n\t\t# (token, pState) = nextToken GenericContext pState\n\t\t# (gcf_generic_info, generic_instance_deps, token, pState)\n\t\t\t= case token of\n\t\t\t\t\/\/ make sure no look ahead occurred in a non GenericContext (defines an offside)\n\t\t\t\tGenericOfToken\n\t\t\t\t\t-> case type_cons of\n\t\t\t\t\t\tTypeConsSymb {type_ident={id_name}}\n\t\t\t\t\t\t\t| id_name==\"OBJECT\" || id_name==\"CONS\" || id_name==\"RECORD\" || id_name==\"FIELD\"\n\t\t\t\t\t\t\t\t# (next_token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t\t-> case next_token of\n\t\t\t\t\t\t\t\t\tIdentToken name\n\t\t\t\t\t\t\t\t\t\t| isLowerCaseName name\n\t\t\t\t\t\t\t\t\t\t\t# (token, pState) = nextToken GenericContext pState\n\t\t\t\t\t\t\t\t\t\t\t# (generic_instance_deps, token, pState) = parse_optional_generic_instance_deps token pState\n\t\t\t\t\t\t\t\t\t\t\t-> (-1, generic_instance_deps, token, pState)\n\t\t\t\t\t\t\t\t\tCurlyOpenToken\n\t\t\t\t\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t\t\t\t-> case token of\n\t\t\t\t\t\t\t\t\t\t\tCurlyCloseToken\n\t\t\t\t\t\t\t\t\t\t\t\t# (token, pState) = nextToken GenericContext pState\n\t\t\t\t\t\t\t\t\t\t\t\t# (generic_instance_deps, token, pState) = parse_optional_generic_instance_deps token pState\n\t\t\t\t\t\t\t\t\t\t\t\t-> (0, generic_instance_deps, token, pState)\n\t\t\t\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t\t\t\t# (generic_info,pState) = parse_info_fields id_name token pState\n\t\t\t\t\t\t\t\t\t\t\t\t (token, pState) = nextToken GenericContext pState\n\t\t\t\t\t\t\t\t\t\t\t\t# (generic_instance_deps, token, pState) = parse_optional_generic_instance_deps token pState\n\t\t\t\t\t\t\t\t\t\t\t\t-> (generic_info,generic_instance_deps, token,pState)\n\t\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t\t# pState = parseError \"derive definition\" (Yes next_token) \"{ or lower case ident\" pState\n\t\t\t\t\t\t\t\t\t\t-> (0, AllGenericInstanceDependencies, token, pState)\n\t\t\t\t\t\t_\n\t\t\t\t\t\t\t-> (0, AllGenericInstanceDependencies, token, pState)\n\t\t\t\tGenericWithToken\n\t\t\t\t\t# (generic_instance_deps, token, pState) = parse_generic_instance_deps 0 0 pState\n\t\t\t\t\t-> (0, generic_instance_deps, token, pState)\n\t\t\t\t_\n\t\t\t\t\t-> (0, AllGenericInstanceDependencies, token, pState)\n\n\t\t# derive_def =\n\t\t\t{\tgc_pos = pos\n\t\t\t,\tgc_type = type\n\t\t\t,\tgc_type_cons = type_cons\n\t\t\t,\tgc_gcf = GCF ident {gcf_gident = generic_ident, gcf_generic = {gi_module=NoIndex,gi_index=NoIndex}, gcf_arity = 0,\n\t\t\t\t\t\t\t\t\tgcf_generic_info = gcf_generic_info, gcf_body = GCB_None, gcf_kind = KindError,\n\t\t\t\t\t\t\t\t\tgcf_generic_instance_deps = generic_instance_deps}\n\t\t\t}\n\t\t= (derive_def, token, pState) \n\n\twant_derive_class_types :: Ident !*ParseState -> ([GenericCaseDef], !*ParseState)\t\t\t\n\twant_derive_class_types class_ident pState\n\t\t# (derive_def, pState) = want_derive_class_type class_ident pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == CommaToken\n\t\t\t# (derive_defs, pState) = want_derive_class_types class_ident pState\n\t\t\t= ([derive_def:derive_defs], pState)\n \t\t\t# pState = wantEndOfDefinition \"derive definition\" (tokenBack pState)\n\t\t\t= ([derive_def], pState)\n\n\twant_derive_class_type :: Ident !*ParseState -> (GenericCaseDef, !*ParseState)\t\t\t\n\twant_derive_class_type class_ident pState\n\t\t# (type, pState) = wantType pState\n\t\t# (ident, pState) = stringToIdent class_ident.id_name (IC_GenericDeriveClass type) pState\n\t\t# (type_cons, pState) = get_type_cons type pState\n\t\t# derive_def = { gc_pos = pos, gc_type = type, gc_type_cons = type_cons,\n\t\t\t\t\t\t gc_gcf = GCFC ident class_ident}\n\t\t= (derive_def, pState)\n\n\tget_type_cons :: Type !*ParseState -> (TypeCons, !*ParseState)\t\n\tget_type_cons (TA type_symb []) pState \n\t\t= (TypeConsSymb type_symb, pState)\n\tget_type_cons (TB tb) pState \n\t\t= (TypeConsBasic tb, pState)\n\tget_type_cons TArrow pState\n\t\t= (TypeConsArrow, pState)\n\tget_type_cons (TV tv) pState\n\t\t| isDclContext parseContext\n\t\t\t= (TypeConsVar tv, pState)\t\t\t \n\tget_type_cons type pState \n\t\t# pState = parseError \"generic type\" No \" type constructor\" pState\n\t\t= (abort \"no TypeCons\", pState)\n\n\tparse_info_fields \"OBJECT\" token pState\n\t\t= parse_OBJECT_info_fields token 0 pState\n\tparse_info_fields \"CONS\" token pState\n\t\t= parse_CONS_info_fields token 0 pState\n\tparse_info_fields \"RECORD\" token pState\n\t\t= parse_RECORD_info_fields token 0 pState\n\tparse_info_fields \"FIELD\" token pState\n\t\t= parse_FIELD_info_fields token 0 pState\n\n\tparse_OBJECT_info_fields token=:(IdentToken name) generic_info pState\n\t\t# field_number=field_n_of_GenericTypeDefDescriptor name\n\t\t| field_number<0\n\t\t\t= (generic_info, parseError \"GenericTypeDefDescriptor\" (Yes token) \"field of GenericTypeDefDescriptor\" pState)\n\t\t# field_mask = 1<0)\n\t\t\t\t\t(parseErrorSimple \"GenericTypeDefDescriptor\" \"field already defined\" pState)\n\t\t\t\t\tpState\n\t\t generic_info = generic_info bitor field_mask\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tCommaToken\n\t\t\t\t# (token,pState) = nextToken FunctionContext pState\n\t\t\t\t-> parse_OBJECT_info_fields token generic_info pState\n\t\t\tCurlyCloseToken\n\t\t\t\t-> (generic_info,pState)\n\t\t\t_\n\t\t\t\t-> (generic_info, parseError \"GenericTypeDefDescriptor record\" (Yes token) \", or }\" pState)\n\tparse_OBJECT_info_fields token generic_info pState\n\t\t= (generic_info, parseError \"GenericTypeDefDescriptor record\" (Yes token) \"field name\" pState)\n\n\tparse_CONS_info_fields token=:(IdentToken name) generic_info pState\n\t\t# field_number=field_n_of_GenericConsDescriptor name\n\t\t| field_number<0\n\t\t\t= (generic_info, parseError \"GenericConsDescriptor\" (Yes token) \"field of GenericConsDescriptor\" pState)\n\t\t# field_mask = 1<0)\n\t\t\t\t\t(parseErrorSimple \"GenericConsDescriptor\" \"field already defined\" pState)\n\t\t\t\t\tpState\n\t\t generic_info = generic_info bitor field_mask\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tCommaToken\n\t\t\t\t# (token,pState) = nextToken FunctionContext pState\n\t\t\t\t-> parse_CONS_info_fields token generic_info pState\n\t\t\tCurlyCloseToken\n\t\t\t\t-> (generic_info,pState)\n\t\t\t_\n\t\t\t\t-> (generic_info, parseError \"GenericConsDescriptor record\" (Yes token) \", or }\" pState)\n\tparse_CONS_info_fields token generic_info pState\n\t\t= (generic_info, parseError \"GenericConsDescriptor record\" (Yes token) \"field name\" pState)\n\n\tparse_RECORD_info_fields token=:(IdentToken name) generic_info pState\n\t\t# field_number=field_n_of_GenericRecordDescriptor name\n\t\t| field_number<0\n\t\t\t= (generic_info, parseError \"GenericRecordDescriptor\" (Yes token) \"field of GenericRecordDescriptor\" pState)\n\t\t# field_mask = 1<0)\n\t\t\t\t\t(parseErrorSimple \"GenericRecordDescriptor\" \"field already defined\" pState)\n\t\t\t\t\tpState\n\t\t generic_info = generic_info bitor field_mask\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tCommaToken\n\t\t\t\t# (token,pState) = nextToken FunctionContext pState\n\t\t\t\t-> parse_RECORD_info_fields token generic_info pState\n\t\t\tCurlyCloseToken\n\t\t\t\t-> (generic_info,pState)\n\t\t\t_\n\t\t\t\t-> (generic_info, parseError \"GenericRecordDescriptor record\" (Yes token) \", or }\" pState)\n\tparse_RECORD_info_fields token generic_info pState\n\t\t= (generic_info, parseError \"GenericRecordDescriptor record\" (Yes token) \"field name\" pState)\n\n\tparse_FIELD_info_fields token=:(IdentToken name) generic_info pState\n\t\t# field_number=field_n_of_GenericFieldDescriptor name\n\t\t| field_number<0\n\t\t\t= (generic_info, parseError \"GenericFieldDescriptor\" (Yes token) \"field of GenericFieldDescriptor\" pState)\n\t\t# field_mask = 1<0)\n\t\t\t\t\t(parseErrorSimple \"GenericFieldDescriptor\" \"field already defined\" pState)\n\t\t\t\t\tpState\n\t\t generic_info = generic_info bitor field_mask\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tCommaToken\n\t\t\t\t# (token,pState) = nextToken FunctionContext pState\n\t\t\t\t-> parse_FIELD_info_fields token generic_info pState\n\t\t\tCurlyCloseToken\n\t\t\t\t-> (generic_info,pState)\n\t\t\t_\n\t\t\t\t-> (generic_info, parseError \"GenericFieldDescriptor record\" (Yes token) \", or }\" pState)\n\tparse_FIELD_info_fields token generic_info pState\n\t\t= (generic_info, parseError \"GenericFieldDescriptor record\" (Yes token) \"field name\" pState)\n\n\tparse_optional_generic_instance_deps GenericWithToken pState\n\t\t= parse_generic_instance_deps 0 0 pState\n\tparse_optional_generic_instance_deps token pState\n\t\t= (AllGenericInstanceDependencies, token, pState)\n\n\tparse_generic_instance_deps n_deps deps pState\n\t\t# (token, pState) = nextToken GenericContext pState\n\t\t= case token of\n\t\t\tWildCardToken\n\t\t\t\t-> parse_generic_instance_deps (n_deps+1) deps pState\n\t\t\tIdentToken name\n\t\t\t | isLowerCaseName name\n\t\t\t\t-> parse_generic_instance_deps (n_deps+1) (deps bitor (1< (GenericInstanceDependencies n_deps deps, token, pState)\n\n\/*\n\tType definitions\n*\/\n\nwantTypeVar :: ! ParseState -> (!TypeVar, !ParseState)\nwantTypeVar pState\n\t# (succ, type_var, pState) = tryTypeVar pState\n\t| succ\n\t\t= (type_var, pState)\n\t\t= wantTypeVarError pState\n\nwantTypeVarT :: !Token !ParseState -> (!TypeVar, !ParseState)\nwantTypeVarT token pState\n\t# (succ, type_var, pState) = tryTypeVarT token pState\n\t| succ\n\t\t= (type_var, pState)\n\t\t= wantTypeVarError pState\n\nwantTypeVarError pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= (MakeTypeVar erroneousIdent, parseError \"Type Variable\" (Yes token) \"type variable\" pState)\n\ntryAttributedTypeVar :: !ParseState -> (!Bool, ATypeVar, !ParseState)\ntryAttributedTypeVar pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| is_type_arg_token token\n\t\t# (aOrA, attr, pState)\t= warnAnnotAndOptionalAttr (tokenBack pState)\n\t (succ, type_var, pState)\t\t= tryTypeVar pState\n\t | succ\n\t\t\t= (True, { atv_attribute = attr, atv_variable = type_var }, pState)\n\t\t| aOrA \/\/ annot <> AN_None || attr <> TA_None\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= (False, no_type_var, parseError \"Attributed type var\" (Yes token) \"type variabele after annotation or attribute\" pState)\n\t\t\/\/ otherwise\n\t \t= (False, no_type_var, tokenBack pState)\n\t\/\/ otherwise\n\t\t= (False, no_type_var, tokenBack pState)\nwhere\t\n\tis_type_arg_token (IdentToken t)\t= isLowerCaseName t\n\tis_type_arg_token DotToken \t= True\n\tis_type_arg_token AsteriskToken \t= True\n\tis_type_arg_token t \t= False\n\t\n\tno_type_var = abort \"tryAttributedTypeVar: No type var\"\n\nwantTypeDef :: !ParseContext !Position !ParseState -> (ParsedDefinition, !ParseState)\nwantTypeDef parseContext pos pState\n\t# (type_lhs, annot, pState)\t= want_type_lhs pos pState\n\t (token, pState)\t\t\t= nextToken TypeContext pState\n\t (def, pState)\t\t\t\t= want_type_rhs token parseContext type_lhs annot pState\n \t pState\t\t\t\t\t= wantEndOfDefinition \"type definition (6)\" pState\n \t= (def, pState)\nwhere\n\twant_type_lhs :: !Position !ParseState -> (!ParsedTypeDef, !Annotation, !ParseState)\n\twant_type_lhs pos pState\n\t\t# (_, annot, attr, pState)\t= optionalAnnotAndAttr pState\n\t\t (name, pState)\t\t\t= wantConstructorName \"Type name\" pState\n\t\t (ident, pState)\t\t\t= stringToIdent name IC_Type pState\n\t\t (args, pState)\t\t\t= parseList tryAttributedTypeVar pState\n\t\t= (MakeTypeDef ident args (ConsList []) attr pos, annot, pState)\n\n\twant_type_rhs :: !Token !ParseContext !ParsedTypeDef !Annotation !ParseState -> (ParsedDefinition, !ParseState)\n\twant_type_rhs EqualToken parseContext td=:{td_ident,td_attribute} annot pState\n\t\t# name\t\t\t\t\t= td_ident.id_name\n\t\t pState\t\t\t\t= verify_annot_attr annot td_attribute name pState\n\t\t (exi_vars, pState)\t= optionalExistentialQuantifiedVariables pState\n\t\t (token, pState)\t\t= nextToken GeneralContext pState \/\/ should be TypeContext\n\t\t= case token of\n\t\t\tCurlyOpenToken\n \t\t\t\t-> want_record_type_rhs name False exi_vars pState\n \t\t\tExclamationToken\n\t\t\t \t# (token, pState) = nextToken TypeContext pState\n \t\t\t\t| token==CurlyOpenToken\n \t\t\t\t\t-> want_record_type_rhs name True exi_vars pState\n\t \t\t \t\t->\t(PD_Type td, parseError \"Record type\" No (\"after ! in definition of record type \"+name+\" { \") pState)\n\t\t\t_\n\t\t\t\t# (condefs, extensible_algebraic_type, pState) = want_constructor_list exi_vars token pState\n\t\t\t\t# td & td_rhs = if extensible_algebraic_type (ExtensibleConses condefs) (ConsList condefs)\n\t\t\t\t| annot == AN_None\n\t \t\t \t\t->\t(PD_Type td, pState)\n\t\t\t\t\t->\t(PD_Type td, parseError \"Algebraic type\" No (\"No lhs strictness annotation for the algebraic type \"+name) pState)\n\twhere\n\t\twant_record_type_rhs name is_boxed_record exi_vars pState\n\t\t\t#\t(fields, pState)\t\t\t= wantFields td_ident pState\n\t\t\t\tpState\t\t\t\t\t\t= wantToken TypeContext \"record type def\" CurlyCloseToken pState\n\t\t\t \t(rec_cons_ident, pState)\t= stringToIdent (\"_\" + name) IC_Expression pState\n\t\t\t=\t(PD_Type { td & td_rhs = SelectorList rec_cons_ident exi_vars is_boxed_record fields }, pState)\n\n\twant_type_rhs ColonDefinesToken parseContext td=:{td_attribute} annot pState \/\/ type synonym\n\t\t# name\t\t\t\t= td.td_ident.id_name\n\t\t pState\t\t\t= verify_annot_attr annot td_attribute name pState\n\t\t (atype, pState)\t= want pState \/\/ Atype\n\t\t td\t\t\t\t= {td & td_rhs = TypeSpec atype}\n\t\t| annot == AN_None\n\t\t\t= (PD_Type td, pState)\n\t\t\t= (PD_Type td, parseError \"Type synonym\" No (\"No lhs strictness annotation for the type synonym \"+name) pState)\n\n\twant_type_rhs DefinesColonToken parseContext td=:{td_ident,td_attribute} annot pState\n\t\t# name\t\t\t\t\t= td_ident.id_name\n\t\t pState\t\t\t\t= verify_annot_attr annot td_attribute name pState\n\t\t (exi_vars, pState)\t= optionalExistentialQuantifiedVariables pState\n\t\t (token, pState)\t\t= nextToken GeneralContext pState\n\t\t (condef, pState)\t\t= want_newtype_constructor exi_vars token pState\n\t\t td\t\t\t\t\t= { td & td_rhs = NewTypeCons condef }\n\t\t| annot == AN_None\n\t \t\t= (PD_Type td, pState)\n\t \t\t= (PD_Type td, parseError \"New type\" No (\"No lhs strictness annotation for the new type \"+name) pState)\n\n\twant_type_rhs token=:OpenToken parseContext td=:{td_attribute} annot pState\n\t\t| isIclContext parseContext\n\t\t\t= (PD_Erroneous, parseError \"type RHS\" (Yes token) \"type definition\" pState)\n\t\t# pState = wantToken TypeContext \"Abstract type synonym\" ColonDefinesToken pState\t\t\t\n\t\t# name\t\t\t\t= td.td_ident.id_name\n\t\t (atype, pState)\t= want pState \/\/ Atype\n\t\t# (td_attribute, properties) = determine_properties annot td_attribute\n\t\t td\t\t\t\t= {td & td_rhs = AbstractTypeSpec properties atype, td_attribute=td_attribute}\n\t\t# pState = wantToken TypeContext \"Abstract type synonym\" CloseToken pState\n\t\t| td_attribute == TA_Anonymous || td_attribute == TA_Unique || td_attribute == TA_None\n\t\t\t= (PD_Type td, pState)\n\t\t\t= (PD_Type td, parseError \"abstract type\" No (\"type attribute \"+toString td_attribute+\" for abstract type \"+name+\" is not\") (tokenBack pState))\n\n\twant_type_rhs BarToken parseContext td=:{td_ident,td_attribute} annot pState\n\t\t# name\t\t\t\t\t= td_ident.id_name\n\t\t pState\t\t\t\t= verify_annot_attr annot td_attribute name pState\n\t\t (exi_vars, pState)\t= optionalExistentialQuantifiedVariables pState\n\t\t (token, pState)\t\t= nextToken GeneralContext pState \/\/ should be TypeContext\n\t\t (condefs, pState)\t\t= want_more_constructors exi_vars token pState\n\t\t (file_name, pState) = getFilename pState\n\t\t module_name = file_name % (0,size file_name-4)\n\t\t (type_ext_ident, pState) = stringToIdent name (IC_TypeExtension module_name) pState\n\t\t td & td_rhs\t\t\t= MoreConses type_ext_ident condefs\n\t\t| annot == AN_None\n\t \t\t= (PD_Type td, pState)\n\t \t\t= (PD_Type td, parseError \"Algebraic type\" No (\"No lhs strictness annotation for the algebraic type \"+name) pState)\n\n\twant_type_rhs token parseContext td=:{td_attribute} annot pState\n\t\t| isIclContext parseContext\n\t\t\t= (PD_Erroneous, parseError \"type RHS\" (Yes token) \"type definition\" pState)\n\t\t\t| td_attribute == TA_Anonymous || td_attribute == TA_Unique || td_attribute == TA_None\n\t\t\t\t# (td_attribute, properties) = determine_properties annot td_attribute\n\t\t\t\t# td = { td & td_attribute = td_attribute, td_rhs = EmptyRhs properties}\n\t\t\t\t= (PD_Type td, tokenBack pState)\n\t\t\t\t# name = td.td_ident.id_name\n\t\t\t\t= (PD_Type { td & td_rhs = EmptyRhs cAllBitsClear}, parseError \"abstract type\" No (\"type attribute \"+toString td_attribute+\" for abstract type \"+name+\" is not\") (tokenBack pState))\n\n\tverify_annot_attr :: !Annotation !TypeAttribute !String !ParseState -> ParseState\n\tverify_annot_attr annot attr name pState\n\t\t| annot <> AN_None\n\t\t\t= parseError \"type definition\" No (\"No annotation, \"+toString annot+\", in the lhs of type \"+name) pState\n\t\t| attr == TA_None || attr == TA_Unique\n\t\t\t= pState\n\t\t\t= parseError \"type definition\" No (\"No attribute, \"+toString attr+\", in the lhs of type \"+name) pState\n\n\tdetermine_properties :: !Annotation !TypeAttribute -> (!TypeAttribute, !BITVECT)\n\tdetermine_properties annot attr\n\t\t| annot == AN_Strict\n\t\t\t| attr == TA_Anonymous\n\t\t\t\t= (TA_None, cIsHyperStrict)\n\t\t\t\t= (attr, cIsHyperStrict bitor cIsNonCoercible)\n\t\t| attr == TA_Anonymous\n\t\t\t= (TA_None, cAllBitsClear)\n\t\t\t= (attr, cIsNonCoercible)\n\n\twant_constructor_list :: ![ATypeVar] !Token !ParseState -> (![ParsedConstructor],!Bool,!ParseState)\n\twant_constructor_list exi_vars DotDotToken pState\n\t\t= ([], True, pState)\n\twant_constructor_list exi_vars token pState\n\t\t# (cons,pState) = want_constructor exi_vars token pState\n\t\t (token, pState) = nextToken TypeContext pState\n\t\t| token == BarToken\n\t\t\t# (exi_vars, pState) = optionalExistentialQuantifiedVariables pState\n\t\t\t (token, pState) = nextToken GeneralContext pState\n\t\t\t (cons_list, extensible_algebraic_type, pState) = want_constructor_list exi_vars token pState\n\t\t\t= ([cons : cons_list], extensible_algebraic_type, pState)\n\t\t\t= ([cons], False, tokenBack pState)\n\n\twant_more_constructors :: ![ATypeVar] !Token !ParseState -> (![ParsedConstructor],!ParseState)\n\twant_more_constructors exi_vars token pState\n\t\t# (cons,pState) = want_constructor exi_vars token pState\n\t\t (token, pState) = nextToken TypeContext pState\n\t\t| token == BarToken\n\t\t\t# (exi_vars, pState) = optionalExistentialQuantifiedVariables pState\n\t\t\t (token, pState) = nextToken GeneralContext pState\n\t\t\t (cons_list, pState) = want_more_constructors exi_vars token pState\n\t\t\t= ([cons : cons_list], pState)\n\t\t\t= ([cons], tokenBack pState)\n\n\twant_constructor :: ![ATypeVar] !Token !ParseState -> (.ParsedConstructor,!ParseState)\n\twant_constructor exi_vars token pState\n\t\t# token = basic_type_to_constructor token\n\t\t# (pc_cons_ident, pc_cons_prio, pc_cons_pos, pState) = want_cons_name_and_prio token pState\n\t\t (pc_arg_types, pState) = parseList tryBrackSAType pState\n\t\t pState = case pc_cons_prio of\n\t\t\t\t\t\tNoPrio\n\t\t\t\t\t\t\t-> pState\n\t\t\t\t\t\tPrio _ _\n\t\t\t\t\t\t\t-> case pc_arg_types of\n\t\t\t\t\t\t\t\t[_,_]\n\t\t\t\t\t\t\t\t\t-> pState\n\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t-> parseErrorSimple pc_cons_ident.id_name \"arity of an infix constructor should be 2\" pState\n\t\t (pc_context,pState) = optional_constructor_context pState\n\t\t cons = {\tpc_cons_ident = pc_cons_ident, pc_arg_types = atypes_from_satypes pc_arg_types, pc_args_strictness=strictness_from_satypes pc_arg_types,\n\t\t\t\t\tpc_context = pc_context, pc_cons_arity = length pc_arg_types, pc_cons_prio = pc_cons_prio, pc_exi_vars = exi_vars, pc_cons_pos = pc_cons_pos}\n\t\t= (cons,pState)\n\n\twant_newtype_constructor :: ![ATypeVar] !Token !ParseState -> (.ParsedConstructor,!ParseState)\n\twant_newtype_constructor exi_vars token pState\n\t\t# token = basic_type_to_constructor token\n\t\t (pc_cons_ident, pc_cons_prio, pc_cons_pos, pState) = want_cons_name_and_prio token pState\n\t\t (succ, pc_arg_type, pState) = trySimpleType TA_Anonymous pState\n\t\t cons = {\tpc_cons_ident = pc_cons_ident, pc_arg_types = [pc_arg_type], pc_args_strictness = NotStrict,\n\t\t \t\t\tpc_context = [], pc_cons_arity = 1, pc_cons_prio = pc_cons_prio, pc_exi_vars = exi_vars, pc_cons_pos = pc_cons_pos}\n\t\t| succ\n\t\t\t= (cons,pState)\n\t\t\t= (cons,parseError \"newtype definition\" No \"type\" pState)\n\n\twant_cons_name_and_prio :: !Token !ParseState -> (Ident, !Priority, !Position, !ParseState)\n\twant_cons_name_and_prio tok=:(IdentToken name) pState\n\t\t# (ident, pState) = stringToIdent name IC_Expression pState\n\t \t (fname, linenr, pState) = getFileAndLineNr pState\n\t \t (token, pState) = nextToken TypeContext pState\n\t \t (prio, pState) = optionalPriority cIsNotInfix token pState\n\t \t| isLowerCaseName name\n\t\t\t= (ident, prio, LinePos fname linenr, parseError \"Algebraic or new type: constructor definitions\" (Yes tok) \"constructor name\" pState)\n\t\t\t= (ident, prio, LinePos fname linenr, pState)\n\twant_cons_name_and_prio OpenToken pState\n\t\t# (name, pState) = wantConstructorName \"infix constructor\" pState\n\t \t (fname, linenr, pState) = getFileAndLineNr pState\n\t\t (ident, pState) = stringToIdent name IC_Expression pState\n\t (token, pState) = nextToken TypeContext (wantToken TypeContext \"type: constructor and prio\" CloseToken pState)\n\t\t (prio, pState) = optionalPriority cIsInfix token pState\n\t\t= (ident, prio, LinePos fname linenr, pState)\n\twant_cons_name_and_prio DotToken pState\n\t\t# (token,pState)\t= nextToken GeneralContext pState\n\t\t= case token of\n\t\t\tIdentToken name\n\t\t\t\t| isFunnyIdName name -> want_cons_name_and_prio (IdentToken (\".\"+name)) pState\n\t\t\t_\t-> (erroneousIdent, NoPrio, NoPos, parseError \"Algebraic or new type: constructor list\" (Yes DotToken) \"constructor name\" (tokenBack pState))\n\twant_cons_name_and_prio token pState\n\t\t= (erroneousIdent, NoPrio, NoPos, parseError \"Algebraic or new type: constructor list\" (Yes token) \"constructor name\" pState)\n\n\tbasic_type_to_constructor IntTypeToken\t\t= IdentToken \"Int\"\n\tbasic_type_to_constructor CharTypeToken\t\t= IdentToken \"Char\"\n\tbasic_type_to_constructor RealTypeToken\t\t= IdentToken \"Real\"\n\tbasic_type_to_constructor BoolTypeToken\t\t= IdentToken \"Bool\"\n\tbasic_type_to_constructor StringTypeToken\t= IdentToken \"String\"\n\tbasic_type_to_constructor FileTypeToken\t\t= IdentToken \"File\"\n\tbasic_type_to_constructor WorldTypeToken\t= IdentToken \"World\"\n\tbasic_type_to_constructor DynamicTypeToken\t= IdentToken \"Dynamic\"\n\tbasic_type_to_constructor token\t\t\t\t= token\n\nmakeAttributeVar name :== { av_ident = name, av_info_ptr = nilPtr }\n\noptionalAnnot :: !ParseState -> (!Bool,!Annotation, !ParseState)\noptionalAnnot pState\n \t# (token, pState) = nextToken TypeContext pState\n \t| token == ExclamationToken\n\t \t# (token, pState) = nextToken TypeContext pState\n\/\/ JVG added for strict lists:\n\t\t| token==SquareCloseToken\n\t\t\t= (False,AN_None,tokenBack (tokenBack pState))\n\t\t= (True, AN_Strict, tokenBack pState)\n\t| otherwise \/\/ token <> ExclamationToken\n\t\t= (False, AN_None, tokenBack pState)\n\noptionalAnnotWithPosition :: !ParseState -> (!Bool,!AnnotationWithPosition, !ParseState)\noptionalAnnotWithPosition pState\n \t# (token, pState) = nextToken TypeContext pState\n \t| token == ExclamationToken\n\t \t# (token, pState) = nextToken TypeContext pState\n\/\/ JVG added for strict lists:\n\t\t| token==SquareCloseToken\n\t\t\t= (False,NoAnnot,tokenBack (tokenBack pState))\n\t\t# (position,pState) = getPosition pState\n\t\t= (True, StrictAnnotWithPosition position, tokenBack pState)\n\t| otherwise \/\/ token <> ExclamationToken\n\t\t= (False, NoAnnot, tokenBack pState)\n\nwarnAnnotAndOptionalAttr :: !ParseState -> (!Bool, !TypeAttribute, !ParseState)\nwarnAnnotAndOptionalAttr pState\n \t# (token, pState) = nextToken TypeContext pState\n \t| token == ExclamationToken\n\t \t# (token, pState) = nextToken TypeContext pState\n\/\/ JVG added for strict lists:\n\t\t| token==SquareCloseToken\n\t\t\t= (False,TA_None,tokenBack (tokenBack pState))\n\t\t# (_ , attr, pState) = tryAttribute token pState\n\t\t# pState = parseWarning \"\" \"! ignored\" pState\n\t\t= (True, attr, pState)\n\t| otherwise \/\/ token <> ExclamationToken\n\t\t= tryAttribute token pState\n\noptionalAnnotAndAttr :: !ParseState -> (!Bool, !Annotation, !TypeAttribute, !ParseState)\noptionalAnnotAndAttr pState\n \t# (token, pState) = nextToken TypeContext pState\n \t| token == ExclamationToken\n\t \t# (token, pState) = nextToken TypeContext pState\n\/\/ JVG added for strict lists:\n\t\t| token==SquareCloseToken\n\t\t\t= (False,AN_None,TA_None,tokenBack (tokenBack pState))\n\t\t# (_ , attr, pState) = tryAttribute token pState\n\t\t= (True, AN_Strict, attr, pState)\n\t| otherwise \/\/ token <> ExclamationToken\n\t\t# (succ, attr, pState) = tryAttribute token pState\n\t\t= (succ, AN_None, attr, pState)\n\noptionalAnnotAndAttrWithPosition :: !ParseState -> (!Bool, !AnnotationWithPosition, !TypeAttribute, !ParseState)\noptionalAnnotAndAttrWithPosition pState\n \t# (token, pState) = nextToken TypeContext pState\n \t| token == ExclamationToken\n\t \t# (token, pState) = nextToken TypeContext pState\n\/\/ JVG added for strict lists:\n\t\t| token==SquareCloseToken\n\t\t\t= (False,NoAnnot,TA_None,tokenBack (tokenBack pState))\n\t\t# (position,pState) = getPosition pState\n\t\t# (_ , attr, pState) = tryAttribute token pState\n\t\t= (True, StrictAnnotWithPosition position, attr, pState)\n\t| otherwise \/\/ token <> ExclamationToken\n\t\t# (succ, attr, pState) = tryAttribute token pState\n\t\t= (succ, NoAnnot, attr, pState)\n\n\/\/ Sjaak 210801 ...\n\t\t \ntryAttribute :: !Token !ParseState -> (!Bool, !TypeAttribute, !ParseState)\ntryAttribute DotToken pState = (True, TA_Anonymous, pState)\ntryAttribute AsteriskToken pState = (True, TA_Unique, pState)\ntryAttribute (IdentToken name) pState\n\t| isLowerCaseName name\n \t# (token, pState) = nextToken TypeContext pState\n\t| ColonToken == token\n\t\t# (ident, pState) = stringToIdent name IC_TypeAttr pState\n\t\t= (True, TA_Var (makeAttributeVar ident), pState)\n\t\t= (False, TA_None, tokenBack (tokenBack pState))\ntryAttribute _\t pState = (False, TA_None, tokenBack pState)\n \n\/\/ ... Sjaak\n\ncIsInfix\t:== True\ncIsNotInfix\t:== False\n\nwantFields :: !Ident !*ParseState -> (![ParsedSelector], !*ParseState)\nwantFields record_type pState\n\t# (field, pState) = want_field record_type pState\n\t (token, pState) = nextToken TypeContext pState\n\t| token == CommaToken\n\t\t# (fields, pState) = wantFields record_type pState\n\t\t= ([field : fields], pState)\n\t\t= ([field], tokenBack pState)\n\twhere\n\t\twant_field :: !Ident !*ParseState -> *(!ParsedSelector, !*ParseState)\n\t\twant_field record_type pState\n\t\t\t# (field_name, pState) \t\t\t= wantLowerCaseName \"record field\" pState\n\t\t\t (fname, linenr, pState)\t\t= getFileAndLineNr pState\n\t\t\t (ps_field_ident, pState) \t\t= stringToIdent field_name (IC_Field record_type) pState\n\t\t\t (ps_selector_ident, pState) \t= stringToIdent field_name IC_Selector pState\n\t\t\t (ps_field_var, pState) \t\t= stringToIdent field_name IC_Expression pState\n\t\t\t pState \t\t\t\t= wantToken TypeContext \"record field\" DoubleColonToken pState\n\/\/\t\t\t (ps_field_type, pState) \t\t= want pState \/\/ wantAType\n\t\t\t (annotation,ps_field_type, pState) = wantAnnotatedAType pState\n\t\t\t= ({ ps_field_ident = ps_field_ident, ps_selector_ident = ps_selector_ident, ps_field_type = ps_field_type,\n\t\t\t\t\tps_field_annotation = annotation,\n\t\t\t\t\tps_field_var = ps_field_var, ps_field_pos = LinePos fname linenr}, pState)\n\n:: SAType = {s_annotation::!Annotation,s_type::!AType}\n\n:: SATypeWithPosition = {sp_annotation::!AnnotationWithPosition,sp_type::!AType}\n\natypes_from_sptypes_and_warn_if_strict :: ![SATypeWithPosition] !ParseState -> (![AType],!ParseState)\natypes_from_sptypes_and_warn_if_strict [] pState\n\t= ([],pState)\natypes_from_sptypes_and_warn_if_strict [{sp_type,sp_annotation}:types] pState\n\t# pState = warnIfStrictAnnot sp_annotation pState\n\t# (atypes,pState) = atypes_from_sptypes_and_warn_if_strict types pState\n\t= ([sp_type:atypes],pState)\n\natypes_from_sptypes :: ![SATypeWithPosition] -> [AType]\natypes_from_sptypes []\n\t= []\natypes_from_sptypes [{sp_type}:types]\n\t= [sp_type:atypes_from_sptypes types]\n\natypes_from_satypes :: ![SAType] -> [AType]\natypes_from_satypes []\n\t= []\natypes_from_satypes [{s_type}:types]\n\t= [s_type:atypes_from_satypes types]\n\nstrictness_from_satypes types\n\t= add_strictness_for_arguments types 0 0 NotStrict\nwhere \n\tadd_strictness_for_arguments :: ![SAType] !Int !Int !StrictnessList -> StrictnessList\n\tadd_strictness_for_arguments [] strictness_index strictness strictness_list\n\t\t| strictness==0\n\t\t\t= strictness_list\n\t\t\t= append_strictness strictness strictness_list\n\tadd_strictness_for_arguments [{s_annotation=AN_Strict}:types] strictness_index strictness strictness_list\n\t\t# (strictness_index,strictness,strictness_list) = add_next_strict strictness_index strictness strictness_list\n\t\t= add_strictness_for_arguments types strictness_index strictness strictness_list\n\tadd_strictness_for_arguments [{s_annotation=AN_None}:types] strictness_index strictness strictness_list\n\t\t# (strictness_index,strictness,strictness_list) = add_next_not_strict strictness_index strictness strictness_list\n\t\t= add_strictness_for_arguments types strictness_index strictness strictness_list\n\nstrictness_from_sptypes types\n\t= add_strictness_for_arguments types 0 0 NotStrict\nwhere \n\tadd_strictness_for_arguments :: ![SATypeWithPosition] !Int !Int !StrictnessList -> StrictnessList\n\tadd_strictness_for_arguments [] strictness_index strictness strictness_list\n\t\t| strictness==0\n\t\t\t= strictness_list\n\t\t\t= append_strictness strictness strictness_list\n\tadd_strictness_for_arguments [{sp_annotation=StrictAnnotWithPosition _}:types] strictness_index strictness strictness_list\n\t\t# (strictness_index,strictness,strictness_list) = add_next_strict strictness_index strictness strictness_list\n\t\t= add_strictness_for_arguments types strictness_index strictness strictness_list\n\tadd_strictness_for_arguments [{sp_annotation=NoAnnot}:types] strictness_index strictness strictness_list\n\t\t# (strictness_index,strictness,strictness_list) = add_next_not_strict strictness_index strictness strictness_list\n\t\t= add_strictness_for_arguments types strictness_index strictness strictness_list\n\nmakeSymbolType args result context attr_env :==\n\t{ st_vars = [], st_args = atypes_from_sptypes args, st_args_strictness = strictness_from_sptypes args,st_arity = length args, st_result = result,\n\t st_context = context, st_attr_env = attr_env, st_attr_vars = [] }\n\nwantSymbolType pState\n\/\/\t# (vars , pState) = optionalUniversalQuantifiedVariables pState \/\/ PK\n\t# (types, pState) = parseList tryBrackSATypeWithPosition pState\n\t (token, pState) = nextToken TypeContext pState\n\t= want_rest_of_symbol_type token types pState\nwhere\n\twant_rest_of_symbol_type :: !Token ![SATypeWithPosition] !ParseState -> (!SymbolType, !ParseState)\n\twant_rest_of_symbol_type ArrowToken types pState\n\t\t# pState\t\t\t\t= case types of\n\t\t\t\t\t\t\t\t\t[]\t-> parseWarning \"want SymbolType\" \"types before -> expected\" pState\n\t\t\t\t\t\t\t\t\t_\t-> pState\n\t\t# (type, pState)\t\t= want pState\n\t\t (context, pState)\t\t= optionalContext pState\n\t\t (attr_env, pState)\t= optionalCoercions pState\n\t\t= (makeSymbolType types type context attr_env, pState)\n\twant_rest_of_symbol_type token [] pState\n\t\t= (makeSymbolType [] (MakeAttributedType TE) [] [], parseError \"symbol type\" (Yes token) \"type\" pState)\n\twant_rest_of_symbol_type token [{sp_type=type,sp_annotation}] pState\n\t\t# pState = warnIfStrictAnnot sp_annotation pState\n\t\t# (context, pState) = optionalContext (tokenBack pState)\n\t\t (attr_env, pState) = optionalCoercions pState\n\t\t= (makeSymbolType [] type context attr_env, pState)\n\twant_rest_of_symbol_type token [{sp_type=type=:{at_type = TA type_symb [] },sp_annotation} : types] pState\n\t\t# pState = warnIfStrictAnnot sp_annotation pState\n\t\t# (atypes,pState) = atypes_from_sptypes_and_warn_if_strict types pState\n\t \t# type = { type & at_type = TA { type_symb & type_arity = length atypes } atypes }\n\t\t (context, pState) = optionalContext (tokenBack pState)\n\t\t (attr_env, pState) = optionalCoercions pState\n\t\t= (makeSymbolType [] type context attr_env, pState)\n\twant_rest_of_symbol_type token [{sp_type=type=:{at_type = TV tv},sp_annotation} : types] pState\n\t\t# pState = warnIfStrictAnnot sp_annotation pState\n\t\t# (atypes,pState) = atypes_from_sptypes_and_warn_if_strict types pState\n\t \t# type = { type & at_type = CV tv :@: atypes }\n\t\t (context, pState) = optionalContext (tokenBack pState)\n\t\t (attr_env, pState) = optionalCoercions pState\n\t\t= (makeSymbolType [] type context attr_env, pState)\n\twant_rest_of_symbol_type token [{sp_type=type=:{at_type = TQualifiedIdent module_ident type_name [] },sp_annotation} : types] pState\n\t\t# pState = warnIfStrictAnnot sp_annotation pState\n\t\t# (atypes,pState) = atypes_from_sptypes_and_warn_if_strict types pState\n\t \t# type = { type & at_type = TQualifiedIdent module_ident type_name atypes }\n\t\t (context, pState) = optionalContext (tokenBack pState)\n\t\t (attr_env, pState) = optionalCoercions pState\n\t\t= (makeSymbolType [] type context attr_env, pState)\n\twant_rest_of_symbol_type token types pState\n\t\t= (makeSymbolType [] (MakeAttributedType TE) [] [], parseError \"symbol type\" (Yes token) \"->\" pState)\n\n\/*\n\tTypes\n*\/\n\nnameToTypeVar name pState\n\t# last_char_index = size name - 1\n\t| name.[last_char_index] == '^'\n\t\t# new_name = name % (0, last_char_index - 1)\n\t\t# (ident, pState) = stringToIdent new_name IC_Type pState\n\t\t= (GTV (MakeTypeVar ident), pState)\n\t\t# (ident, pState) = stringToIdent name IC_Type pState\n\t\t= (TV (MakeTypeVar ident), pState)\n\ninstance want TypeVar\nwhere\n\twant pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t= case token of\n\t\t\tIdentToken name\n\t\t\t\t| isLowerCaseName name\n\t\t\t\t\t# (ident, pState) = stringToIdent name IC_Type pState\n\t\t\t\t\t-> (MakeTypeVar ident, pState)\n\t\t\t\t\t-> (MakeTypeVar erroneousIdent, parseError \"Type variable\" (Yes token) \"\" pState)\n\t\t\t_\n\t\t\t\t-> (MakeTypeVar erroneousIdent, parseError \"Type variable\" (Yes token) \"\" pState)\n\n\/\/ Sjaak 210801 ...\n\nadjustAttribute :: !TypeAttribute Type *ParseState -> (!TypeAttribute, !*ParseState)\nadjustAttribute attr (TV {tv_ident}) pState\n\t= adjustAttributeOfTypeVariable attr tv_ident pState\nadjustAttribute attr (GTV {tv_ident}) pState\n\t= adjustAttributeOfTypeVariable attr tv_ident pState\nadjustAttribute attr type pState\n\t= (attr, pState)\n\nadjustAttributeOfTypeVariable :: !TypeAttribute !Ident !*ParseState -> (!TypeAttribute, !*ParseState)\nadjustAttributeOfTypeVariable TA_Anonymous {id_name} pState\n\t# (ident, pState) = stringToIdent id_name IC_TypeAttr pState\n\t= (TA_Var (makeAttributeVar ident), pState)\nadjustAttributeOfTypeVariable attr _ pState\n\t= (attr, pState)\n\n\/\/ ... Sjaak 210801\n\nstringToType :: !String !ParseState -> (!Type, !ParseState)\nstringToType name pState\n\t| isLowerCaseName name\n\t\t= nameToTypeVar name pState\n\t\t# (id, pState) = stringToIdent name IC_Type pState\n\t\t= (TA (MakeNewTypeSymbIdent id 0) [], pState)\n\/*\t| isUpperCaseName name\n\t\t= (TA (MakeNewTypeSymbIdent id 0) [], pState)\n\t\t= nameToTypeVar name pState\n*\/\n\/*\nstringToAType :: !String !Annotation !TypeAttribute !ParseState -> (!AType, !ParseState)\nstringToAType name annot attr pState\n\t# (id, pState) = stringToIdent name IC_Type pState\n\t| isUpperCaseName name\n\t\t= ({ at_annotation = annot, at_attribute = attr, at_type = TA (MakeNewTypeSymbIdent id 0) []}, pState)\n\t\t# (type_var, pState) = nameToTypeVar name pState\n\t\t= build_attributed_type_var attr annot type_var name pState\nwhere\n\tbuild_attributed_type_var TA_Anonymous annot type_var type_var_name pState\n\t\t# (attr_id, pState) = stringToIdent type_var_name IC_TypeAttr pState\n\t\t= ({ at_annotation = annot, at_attribute = TA_Var (makeAttributeVar attr_id), at_type = type_var }, pState)\n\tbuild_attributed_type_var attr annot type_var _ pState\n\t\t= ({ at_annotation = annot, at_attribute = attr, at_type = type_var }, pState)\n*\/\n\ninstance want SAType\nwhere\n\twant pState\n\t\t# (annotation,a_type,pState) = wantAnnotatedAType pState\n\t\t= ({s_annotation=annotation,s_type=a_type},pState)\n\n:: AnnotationWithPosition = NoAnnot | StrictAnnotWithPosition !FilePosition;\n\nwantAnnotatedATypeWithPositionT :: !Token !ParseState -> (!AnnotationWithPosition,!AType,!ParseState)\nwantAnnotatedATypeWithPositionT ForAllToken pState\n\t# (vars, pState)\t\t= wantUniversalQuantifiedVariables pState\n\t# (_,annotation,pState) = optionalAnnotWithPosition pState\n\t# (succ, atype, pState)\t= tryAnnotatedAType TA_None pState\n\t# atype = {atype & at_type = TFA vars atype.at_type}\n\t| succ\n\t\t= (annotation, atype, pState)\n\t\t= (annotation, atype, attributed_and_annotated_type_error pState)\nwantAnnotatedATypeWithPositionT noForAllToken pState\n\t= wantAnnotatedATypeWithPosition_noUniversalQuantifiedVariables (tokenBack pState)\n\nwantAnnotatedATypeWithPosition_noUniversalQuantifiedVariables pState\n\t# (_,annotation,pState) = optionalAnnotWithPosition pState\n\t# (succ, atype, pState)\t= tryAnnotatedAType TA_None pState\n\t| succ\n\t\t= (annotation, atype, pState)\n\t\t= (annotation, atype, attributed_and_annotated_type_error pState)\n\nwantAnnotatedAType :: !ParseState -> (!Annotation,!AType,!ParseState)\nwantAnnotatedAType pState\n\t# (vars , pState)\t\t= optionalUniversalQuantifiedVariables pState\t\n\t# (_,annotation,pState) = optionalAnnot pState\n\t| isEmpty vars\n\t\t# (succ, atype, pState)\t= tryAnnotatedAType TA_None pState\n\t\t| succ\n\t\t\t= (annotation, atype, pState)\n\t\t\t= (annotation, atype, attributed_and_annotated_type_error pState)\n\t\t# (succ, atype, pState)\t= tryAnnotatedAType TA_None pState\n\t\t# atype = {atype & at_type = TFA vars atype.at_type}\n\t\t| succ\n\t\t\t= (annotation, atype, pState)\n\t\t\t= (annotation, atype, attributed_and_annotated_type_error pState)\n\ntryAnnotatedAType :: !TypeAttribute !ParseState -> (!Bool, !AType,!ParseState)\ntryAnnotatedAType attr pState\n\t# (types, pState)\t\t= parseList tryBrackAType pState\n\t| isEmpty types\n\t\t= (False, {at_attribute = attr, at_type = TE}, pState)\n\t# (token, pState)\t\t= nextToken TypeContext pState\n\t| token == ArrowToken\n\t\t# (rtype, pState)\t= wantAType pState\n\t\t atype = make_curry_type attr types rtype\n\t\t= ( True, atype, pState)\n\t\/\/ otherwise (note that types is non-empty)\n\t# (atype, pState) = convertAAType types attr (tokenBack pState)\n\t= (True, atype, pState)\nwhere\n\tmake_curry_type attr [t1] res_type\n\t\t= {at_attribute = attr, at_type = t1 --> res_type}\n\tmake_curry_type attr [t1:tr] res_type\n\t\t= {at_attribute = attr, at_type = t1 --> make_curry_type TA_None tr res_type}\n\tmake_curry_type _ _ _ = abort \"make_curry_type: wrong assumption\"\n\n:: ParseResult :== Int\nParseOk:==0\nParseFailWithError:==1\nParseFailWithoutError:==2\n\ntryBrackAType_allow_universal_quantifier :: !TypeAttribute !ParseState -> (!Bool, AType, !ParseState)\ntryBrackAType_allow_universal_quantifier attr pState\n\t# (token, pState) = nextToken TypeContext pState\n\t# (result,atype,pState) = tryBrackATypeT_allow_universal_quantifier token attr pState\n\t= (result==ParseOk,atype,pState)\n\ntryBrackATypeT_allow_universal_quantifier :: !Token !TypeAttribute !ParseState -> (!ParseResult, AType, !ParseState)\ntryBrackATypeT_allow_universal_quantifier OpenToken attr pState\n\t\/\/ type of function or constructor argument\n\t# (token, pState) = nextToken TypeContext pState\n\t= case token of\n\t\tForAllToken\n\t\t\t# (vars,pState) = wantUniversalQuantifiedVariables pState \n\t\t\t (annot_with_pos, atype, pState) = wantAnnotatedATypeWithPosition_noUniversalQuantifiedVariables pState\n\t\t\t (token, pState) = nextToken TypeContext pState\n\t\t\t-> case token of\n\t\t\t\tBarToken\n\t\t\t\t\t# (contexts, pState) = want_contexts pState\n\t\t\t\t\t (token, pState) = nextToken TypeContext pState\n\t\t\t\t\t (succ,atype,pState)\n\t\t\t\t\t\t= case token of\n\t\t\t\t\t\t\tCloseToken\n\t\t\t\t\t\t\t\t# type = atype.at_type\n\t\t\t\t\t\t\t\t (attr, pState) = determAttr attr atype.at_attribute type pState\n\t\t\t\t\t\t\t\t pState = warnIfStrictAnnot annot_with_pos pState\n\t\t\t\t\t\t\t\t-> (ParseOk, {at_attribute = attr, at_type = type}, pState)\n\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t-> (ParseFailWithError, atype, parseError \"Simple type\" (Yes token) \"')' or ','\" pState)\n\t\t\t\t\t atype = {atype & at_type = TFAC vars atype.at_type contexts}\n\t\t\t\t\t-> (succ, atype, pState)\n\t\t\t\t_\n\t\t\t\t\t# atype = {atype & at_type = TFA vars atype.at_type}\n\t\t\t\t\t-> trySimpleTypeT_after_OpenToken_and_type token annot_with_pos atype attr pState\n\t\t_\n\t\t\t-> trySimpleTypeT_after_OpenToken token attr pState\ntryBrackATypeT_allow_universal_quantifier token attr pState\n\t= trySimpleTypeT token attr pState\n\ntryBrackSATypeWithPosition :: !ParseState -> (!Bool, SATypeWithPosition, !ParseState)\ntryBrackSATypeWithPosition pState\n\t\/\/ type of function argument\n\t# (succ, annot, attr, pState) = optionalAnnotAndAttrWithPosition pState\n\t| succ\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t# (result, atype, pState) = tryBrackATypeT_allow_universal_quantifier token attr pState\n\t\t# sa_type_wp = {sp_annotation=annot,sp_type=atype}\n\t\t| result==ParseOk\n\t\t\t= (True, sa_type_wp, pState)\n\t\t| result==ParseFailWithError\n\t\t\t= (False, sa_type_wp, pState)\n\t\t\t= (False, sa_type_wp, parseError \"symbol type\" (Yes token) \"type\" pState)\n\t\t# (succ, atype, pState) = tryBrackAType_allow_universal_quantifier attr pState\n\t\t= (succ, {sp_annotation=annot,sp_type=atype}, pState)\n\ntryBrackSAType :: !ParseState -> (!Bool, SAType, !ParseState)\ntryBrackSAType pState\n\t\/\/ type of constructor argument\n\t# (succ, annot, attr, pState) = optionalAnnotAndAttr pState\n\t| succ\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t# (result, atype, pState) = tryBrackATypeT_allow_universal_quantifier token attr pState\n\t\t# sa_type = {s_annotation=annot,s_type=atype}\n\t\t| result==ParseOk\n\t\t\t= (True, sa_type, pState)\n\t\t| result==ParseFailWithError\n\t\t\t= (False, sa_type, pState)\n\t\t\t= (False, sa_type, parseError \"constructor type\" (Yes token) \"type\" pState)\n\t\t# (succ, atype, pState) = tryBrackAType_allow_universal_quantifier attr pState\n\t\t= (succ, {s_annotation=annot,s_type=atype}, pState)\n\ninstance want AType\nwhere\n\twant pState = wantAType pState\n\ninstance want Type\nwhere\n\twant pState = wantType pState\n\nwantType :: !ParseState -> (!Type,!ParseState)\nwantType pState\n\t# (vars, pState)\t= optionalUniversalQuantifiedVariables pState\n\t| isEmpty vars\n\t\t# (succ, atype, pState)\t= tryAType False TA_None pState\n\t\t (succ2, type, pState)\t= tryATypeToType atype pState\n\t\t| succ&&succ2\n\t\t\t= (type, pState)\n\t\t\/\/ otherwise \/\/~ succ\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= (type, parseError \"type\" (Yes token) \"type\" pState)\n\t\/\/ ~(isEmpty vars)\n\t\t# (type, pState) = wantType pState\n\t\t= (TFA vars type, pState)\n\nwantAType :: !ParseState -> (!AType,!ParseState)\nwantAType pState\n\t# (succ, atype, pState)\t= tryAType True TA_None pState\n\t| succ\n\t\t= (atype, pState)\n\t\t= (atype, attributed_and_annotated_type_error pState)\n\nattributed_and_annotated_type_error pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= parseError \"atype\" (Yes token) \"attributed and annotated type\" pState\n\ntryType :: !ParseState -> (!Bool,!Type,!ParseState)\ntryType pState\n\t# (succ, atype, pState)\t= tryAType False TA_None pState\n\t (succ2, type, pState)\t= tryATypeToType atype pState\n\t= (succ&&succ2, type, pState)\n\ntryAType :: !Bool !TypeAttribute !ParseState -> (!Bool,!AType,!ParseState)\ntryAType tryAA attr pState\n\t# (vars , pState)\t\t= optionalUniversalQuantifiedVariables pState\n\t# (types, pState)\t\t= parseList tryBrackAType pState\n\t| isEmpty types\n\t\t| isEmpty vars\n\t\t\t= (False, {at_attribute = attr, at_type = TE}, pState)\n\t\t\/\/ otherwise \/\/ PK\n\t\t\t# (token, pState) = nextToken TypeContext pState\n\t\t\t= (False, {at_attribute = attr, at_type = TFA vars TE}\n\t\t\t , parseError \"annotated type\" (Yes token) \"type\" (tokenBack pState))\n\t# (token, pState)\t\t= nextToken TypeContext pState\n\t| token == ArrowToken\n\t\t# (rtype, pState)\t= wantAType pState\n\t\t atype = make_curry_type attr types rtype\n\t\t| isEmpty vars\n\t\t\t= ( True, atype, pState)\n\t\t\t= ( True, { atype & at_type = TFA vars atype.at_type }, pState)\n\t\/\/ otherwise (not that types is non-empty)\n\/\/ Sjaak\t\n\t# (atype, pState) = convertAAType types attr (tokenBack pState)\n\t| isEmpty vars\n\t\t= (True, atype, pState)\n\t\t= (True, { atype & at_type = TFA vars atype.at_type }, pState)\n\/* PK\ntryFunctionType :: ![AType] !Annotation !TypeAttribute !ParseState -> (!Bool,!AType,!ParseState)\ntryFunctionType types annot attr pState\n\t# (rtype, pState)\t\t= wantAType pState\n\t= ( True\n\t , make_curry_type annot attr types rtype\n\t , pState\n\t )\n*\/\nwhere\n\tmake_curry_type attr [t1] res_type\n\t\t= {at_attribute = attr, at_type = t1 --> res_type}\n\tmake_curry_type attr [t1:tr] res_type\n\t\t= {at_attribute = attr, at_type = t1 --> make_curry_type TA_None tr res_type}\n\tmake_curry_type _ _ _ = abort \"make_curry_type: wrong assumption\"\n\n\/\/ Sjaak ...\nconvertAAType :: ![AType] !TypeAttribute !ParseState -> (!AType,!ParseState)\nconvertAAType [atype] attr pState\n\t# type\t\t\t\t= atype.at_type\n\t# (attr, pState)\t= determAttr attr atype.at_attribute type pState\n\t= ( {at_attribute = attr, at_type = type}, pState)\nconvertAAType [atype:atypes] attr pState\n\t# type\t\t\t\t= atype.at_type\n\t# (attr, pState)\t= determAttr_ attr atype.at_attribute type pState\n\t\twith\n\t\t\tdetermAttr_ :: !TypeAttribute !TypeAttribute !Type !ParseState -> (!TypeAttribute, !ParseState)\n\t\t\tdetermAttr_ TA_None (TA_Var {av_ident}) (TV {tv_ident}) pState\n\t\t\t\t| av_ident.id_name==tv_ident.id_name\n\t\t\t\t\t= (TA_Anonymous,pState)\n\t\t\tdetermAttr_ attr1 attr2 type pState\n\t\t\t\t= determAttr attr1 attr2 type pState\n\t# (type, pState)\t= convert_list_of_types atype.at_type atypes pState\n\t= ({at_attribute = attr, at_type = type}, pState)\nwhere\n\tconvert_list_of_types (TA sym []) types pState\n\t\t= (TA { sym & type_arity = length types } types, pState)\n\tconvert_list_of_types (TV tv) types pState\n\t\t= (CV tv :@: types, pState)\n\tconvert_list_of_types TArrow [type1, type2]\tpState\n\t\t= (type1 --> type2, pState)\n\tconvert_list_of_types TArrow [type1] pState\n\t\t= (TArrow1 type1, pState)\n\tconvert_list_of_types (TArrow1 type1) [type2] pState\n\t\t= (type1 --> type2, pState)\n\tconvert_list_of_types (TQualifiedIdent module_ident type_name []) types pState\n\t\t= (TQualifiedIdent module_ident type_name types, pState)\n\tconvert_list_of_types _ types pState\n\t\t= (TE, parseError \"Type\" No \"ordinary type variable\" pState)\n\/\/ ... Sjaak\n\/*\ntryApplicationType _ annot attr pState\n\t= (False, {at_annotation = annot, at_attribute = attr, at_type = TE}, pState)\n*\/\ntryBrackType :: !ParseState -> (!Bool, Type, !ParseState)\ntryBrackType pState\n\t# (succ, atype, pState) \t= trySimpleType TA_None pState\n\t (succ2, type, pState)\t\t= tryATypeToType atype pState\n\t= (succ&&succ2, type, pState)\n\ntryBrackAType :: !ParseState -> (!Bool, AType, !ParseState)\ntryBrackAType pState\n\t# (_, attr, pState)\t= warnAnnotAndOptionalAttr pState\n\t= trySimpleType attr pState\n\ntrySimpleType :: !TypeAttribute !ParseState -> (!Bool, !AType, !ParseState)\ntrySimpleType attr pState\n\t# (token, pState)\t\t= nextToken TypeContext pState\n\t# (result,atype,pState) = trySimpleTypeT token attr pState\n\t= (result==ParseOk,atype,pState)\n\nis_tail_strict_list_or_nil pState\n\t# (square_close_position, pState) = getPosition pState\n\t# pState=tokenBack pState\n\t# (exclamation_position, pState) = getPosition pState\n\t# pState=tokenBack pState\n\t# (square_open_position, pState) = getPosition pState\n\t# (exclamation_token,pState) = nextToken TypeContext pState\n\t# (square_close_token,pState) = nextToken TypeContext pState\n\t| exclamation_position.fp_col+1==square_close_position.fp_col && exclamation_position.fp_line==square_close_position.fp_line\n\t\t&& (square_open_position.fp_col+1<>exclamation_position.fp_col || square_open_position.fp_line<>exclamation_position.fp_line)\n\t\t= (True,pState)\n\t\t= (False,pState)\n\ntrySimpleTypeT :: !Token !TypeAttribute !ParseState -> (!ParseResult, !AType, !ParseState)\ntrySimpleTypeT (IdentToken id) attr pState\n\t| isLowerCaseName id\n\t\t# (typevar, pState)\t= nameToTypeVar id pState\n\t\t (attr, pState)\t= adjustAttribute attr typevar pState\n\t\t= (ParseOk, {at_attribute = attr, at_type = typevar}, pState)\n\t| otherwise \/\/ | isUpperCaseName id || isFunnyIdName id\n\t# (type, pState) = stringToType id pState\n\t= (ParseOk, {at_attribute = attr, at_type = type}, pState)\ntrySimpleTypeT SquareOpenToken attr pState\n\t# (token, pState) = nextToken TypeContext pState\n\t# (head_strictness,token,pState) = wantHeadStrictness token pState\n\t\twith\n\t\t\twantHeadStrictness :: Token *ParseState -> *(!Int,!Token,!*ParseState)\n\t\t\twantHeadStrictness ExclamationToken pState\n\t\t\t\t# (token,pState) = nextToken TypeContext pState\n\t\t\t\t= (HeadStrict,token,pState)\n\t\t\twantHeadStrictness HashToken pState\n\t\t\t\t# (token,pState) = nextToken TypeContext pState\n\t\t\t\t= (HeadUnboxed,token,pState)\n\t\t\twantHeadStrictness token pState\n\t\t\t\t= (HeadLazy,token,pState)\n\t| token == SquareCloseToken\n\t\t| head_strictness==HeadStrict\n\t\t\t# (tail_strict,pState) = is_tail_strict_list_or_nil pState\n\t\t\t| tail_strict\n\t\t\t\t# list_symbol = makeTailStrictListTypeSymbol HeadLazy 0\n\t\t \t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol []}, pState)\t\t\t\t\t\n\t\t\t\t# list_symbol = makeListTypeSymbol head_strictness 0\n\t\t \t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol []}, pState)\n\t\t# list_symbol = makeListTypeSymbol head_strictness 0\n \t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol []}, pState)\n\n\t| token==ExclamationToken\n\t\t# (token,pState) = nextToken TypeContext pState\n\t\t| token==SquareCloseToken\n\t\t\t# list_symbol = makeTailStrictListTypeSymbol head_strictness 0\n \t\t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol []}, pState)\n\t\t\t= (ParseFailWithError, {at_attribute = attr, at_type = TE}, parseError \"List type\" (Yes token) \"]\" pState)\n\n\t# (type, pState)\t= wantAType (tokenBack pState)\n\t (token, pState)\t= nextToken TypeContext pState\n\t| token == SquareCloseToken\n\t\t# list_symbol = makeListTypeSymbol head_strictness 1\n\t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol [type]}, pState)\n\n\t| token==ExclamationToken\n\t\t# (token,pState) = nextToken TypeContext pState\n\t\t| token==SquareCloseToken\n\t\t\t# list_symbol = makeTailStrictListTypeSymbol head_strictness 1\n\t\t\t= (ParseOk, {at_attribute = attr, at_type = TA list_symbol [type]}, pState)\n\t\t\t= (ParseFailWithError, {at_attribute = attr, at_type = TE}, parseError \"List type\" (Yes token) \"]\" pState)\n\n\t\/\/ otherwise \/\/ token <> SquareCloseToken\n\t\t= (ParseFailWithError, {at_attribute = attr, at_type = TE}, parseError \"List type\" (Yes token) \"]\" pState)\ntrySimpleTypeT OpenToken attr pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= trySimpleTypeT_after_OpenToken token attr pState\ntrySimpleTypeT CurlyOpenToken attr pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == CurlyCloseToken\n\t\t# array_symbol = makeLazyArraySymbol 0\n\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol []}, pState)\n\t| token == HashToken\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == CurlyCloseToken\n\t\t\t# array_symbol = makeUnboxedArraySymbol 0\n\t\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol []}, pState)\n\t\t\/\/ otherwise \/\/ token <> CurlyCloseToken\n\t \t\t# (atype, pState)\t\t\t= wantAType (tokenBack pState)\n \t\t\t pState\t\t\t\t\t= wantToken TypeContext \"unboxed array type\" CurlyCloseToken pState\n \t\t\t array_symbol = makeUnboxedArraySymbol 1\n \t\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol [atype]}, pState)\n\t| token == ExclamationToken\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| token == CurlyCloseToken\n\t\t\t# array_symbol = makeStrictArraySymbol 0\n\t\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol []}, pState)\n\t\t\/\/ otherwise \/\/ token <> CurlyCloseToken\n\t \t\t# (atype,pState)\t\t\t= wantAType (tokenBack pState)\n \t\t\t pState\t\t\t\t\t= wantToken TypeContext \"strict array type\" CurlyCloseToken pState\n \t\t\t array_symbol = makeStrictArraySymbol 1\n \t\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol [atype]}, pState)\n \t\/\/ otherwise\n \t\t# (atype,pState)\t\t\t= wantAType (tokenBack pState)\n \t\t pState\t\t\t\t\t= wantToken TypeContext \"lazy array type\" CurlyCloseToken pState\n\t\t array_symbol = makeLazyArraySymbol 1\n\t\t= (ParseOk, {at_attribute = attr, at_type = TA array_symbol [atype]}, pState)\ntrySimpleTypeT StringTypeToken attr pState\n\t# type = makeStringType\n\t= (ParseOk, {at_attribute = attr, at_type = type}, pState)\ntrySimpleTypeT (QualifiedIdentToken module_name ident_name) attr pState\n\t| not (isLowerCaseName ident_name)\n\t\t# (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Type pState\n\t\t# type = TQualifiedIdent module_id ident_name []\n\t\t= (ParseOk, {at_attribute = attr, at_type = type}, pState)\ntrySimpleTypeT token attr pState\n\t# (bt, pState) = try token pState\n\t= case bt of\n\t\tYes bt\t-> (ParseOk , {at_attribute = attr, at_type = TB bt}, pState)\n\t\tno\t\t-> (ParseFailWithoutError, {at_attribute = attr, at_type = TE} , pState)\n\ntrySimpleTypeT_after_OpenToken :: !Token !TypeAttribute !ParseState -> (!ParseResult, !AType, !ParseState)\ntrySimpleTypeT_after_OpenToken CommaToken attr pState\n\t# (tup_arity, pState)\t\t= determine_arity_of_tuple 2 pState\n\t tuple_symbol = makeTupleTypeSymbol tup_arity 0\n\t= (ParseOk, {at_attribute = attr, at_type = TA tuple_symbol []}, pState)\t\n where\n\tdetermine_arity_of_tuple :: !Int !ParseState -> (!Int, !ParseState)\n\tdetermine_arity_of_tuple arity pState\n\t\t# (token, pState) = nextToken TypeContext pState\n\t\t| CommaToken == token\n \t\t\t= determine_arity_of_tuple (inc arity) pState\n\t\t| CloseToken == token\n\t\t\t= (arity, pState)\n\t\t\t= (arity, parseError \"tuple type\" (Yes token) \")\" pState)\ntrySimpleTypeT_after_OpenToken ArrowToken attr pState\n\t# (token, pState) = nextToken TypeContext pState\n\t| token == CloseToken\n\t\t= (ParseOk, {at_attribute = attr, at_type = TArrow}, pState)\n\t\t= (ParseFailWithError,{at_attribute = attr, at_type = TE},\n\t\t\tparseError \"arrow type\" (Yes token) \")\" pState)\ntrySimpleTypeT_after_OpenToken CloseToken attr pState\n\t#! unit_type_ident = predefined_idents.[PD_UnitType]\n\t= (ParseOk,{at_attribute=attr,at_type=TA (MakeNewTypeSymbIdent unit_type_ident 0) []},pState)\ntrySimpleTypeT_after_OpenToken token attr pState\n\t# (annot_with_pos,atype, pState) = wantAnnotatedATypeWithPositionT token pState\n\t (token, pState)\t= nextToken TypeContext pState\n\t= trySimpleTypeT_after_OpenToken_and_type token annot_with_pos atype attr pState\n\ntrySimpleTypeT_after_OpenToken_and_type CloseToken annot_with_pos atype attr pState\n\t# type\t\t\t\t= atype.at_type\n\t (attr, pState)\t= determAttr attr atype.at_attribute type pState\n\t pState = warnIfStrictAnnot annot_with_pos pState\n\t= (ParseOk, {at_attribute = attr, at_type = type}, pState)\ntrySimpleTypeT_after_OpenToken_and_type CommaToken annot_with_pos atype attr pState\n\t\/\/ TupleType\n\t# (satypes, pState)\t= wantSequence CommaToken TypeContext pState\n\t pState\t\t\t= wantToken TypeContext \"tuple type\" CloseToken pState\n\t satypes\t\t\t= [{s_annotation=(case annot_with_pos of NoAnnot -> AN_None; StrictAnnotWithPosition _ -> AN_Strict),s_type=atype}:satypes]\n\t arity\t\t\t\t= length satypes\n \t tuple_symbol = makeTupleTypeSymbol arity arity\n\t= (ParseOk, {at_attribute = attr, at_type = TAS tuple_symbol (atypes_from_satypes satypes) (strictness_from_satypes satypes)}, pState)\ntrySimpleTypeT_after_OpenToken_and_type token annot_with_pos atype attr pState\n\t= (ParseFailWithError, atype, parseError \"Simple type\" (Yes token) \"')' or ','\" pState)\n\ninstance try BasicType\nwhere\n\ttry IntTypeToken\t pState = (Yes BT_Int\t\t\t, pState)\n\ttry CharTypeToken\t pState\t= (Yes BT_Char\t\t\t, pState)\n\ttry BoolTypeToken\t pState\t= (Yes BT_Bool\t\t\t, pState)\n\ttry RealTypeToken\t pState\t= (Yes BT_Real\t\t\t, pState)\n\ttry DynamicTypeToken pState\t= (Yes BT_Dynamic\t\t, {pState & ps_flags=pState.ps_flags bitor PS_DynamicTypeUsedMask})\n\ttry FileTypeToken\t pState = (Yes BT_File\t\t\t, pState)\n\ttry WorldTypeToken\t pState = (Yes BT_World\t\t\t, pState)\n\ttry _\t\t\t\t pState = (No\t\t\t\t\t, tokenBack pState)\n\ndetermAnnot :: !Annotation !Annotation !ParseState -> (!Annotation, !ParseState)\ndetermAnnot AN_None annot2 pState = (annot2, pState)\ndetermAnnot annot1 AN_None pState = (annot1, pState)\ndetermAnnot annot1 annot2 pState\n\t= (annot1, parseError \"simple type\" No (\"More type annotations, \"+toString annot1+\" and \"+toString annot2+\", than\") pState)\n\ndetermAttr :: !TypeAttribute !TypeAttribute !Type !ParseState -> (!TypeAttribute, !ParseState)\ndetermAttr TA_None attr2 type pState = adjustAttribute attr2 type pState\ndetermAttr attr1 TA_None type pState = adjustAttribute attr1 type pState\ndetermAttr attr1 attr2 type pState\n\t= (attr1, parseError \"simple type\" No (\"More type attributes, \"+toString attr1+\" and \"+toString attr2+\", than\") pState)\n\nwantDynamicTypeInExpression :: !*ParseState -> *(!DynamicType,!*ParseState)\nwantDynamicTypeInExpression pState \n\t# (atype, pState) = want pState\n\t= case atype.at_type of\n\t\tTFA vars type\n\t\t\t# atype = {atype & at_type=type}\n\t\t\t (contexts, pState) = optionalContext pState\n\t\t\t-> ({dt_uni_vars=vars, dt_type=atype, dt_global_vars=[], dt_contexts=contexts}, pState)\n\t\t_\n\t\t\t-> ({dt_uni_vars=[], dt_type=atype, dt_global_vars=[], dt_contexts=[]}, pState)\n\nwantDynamicTypeInPattern :: !*ParseState -> *(!DynamicType,!*ParseState)\nwantDynamicTypeInPattern pState \n\t# (atype, pState) = want pState\n\t= case atype.at_type of\n\t\tTFA vars type\n\t\t\t# atype = {atype & at_type=type}\n\t\t\t (contexts, pState) = optionalContext pState\n\t\t\t-> ({dt_uni_vars=vars, dt_type=atype, dt_global_vars=[], dt_contexts=contexts}, pState)\n\t\t_\n\t\t\t # (contexts, pState) = optionalContext pState\n\t\t\t-> ({dt_uni_vars=[], dt_type=atype, dt_global_vars=[], dt_contexts=contexts}, pState)\n\noptionalExistentialQuantifiedVariables :: !*ParseState -> *(![ATypeVar],!*ParseState)\noptionalExistentialQuantifiedVariables pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= case token of\n\t\tExistsToken\n\t\t\t# (vars, pState) = wantList \"existential quantified variable(s)\" tryQuantifiedTypeVar pState\n\t\t\t-> (vars, wantToken TypeContext \"Existential Quantified Variables\" ColonToken pState)\n\t\t_\t-> ([], tokenBack pState)\n\n\/* Sjaak 041001\nwhere\n\ttry_existential_type_var :: !ParseState -> (Bool,ATypeVar,ParseState)\n\ttry_existential_type_var pState\n\t\t# (token, pState)\t= nextToken TypeContext pState\n\t\t= case token of\n\t\t\tDotToken\n\t\t\t\t# (typevar, pState)\t= wantTypeVar pState\n\t\t\t\t-> (True, {atv_attribute = TA_Anonymous, atv_annotation = AN_None, atv_variable = typevar}, pState)\n\t\t\t_\n\t\t\t\t# (succ, typevar, pState)\t= tryTypeVarT token pState\n\t\t\t\t| succ\n\t\t\t\t\t#\tatypevar = {atv_attribute = TA_None, atv_annotation = AN_None, atv_variable = typevar}\n\t\t\t\t\t->\t(True,atypevar,pState)\n\t\t\t\t\t->\t(False,abort \"no ATypeVar\",pState)\n*\/\n\noptionalUniversalQuantifiedVariables :: !*ParseState -> *(![ATypeVar],!*ParseState)\noptionalUniversalQuantifiedVariables pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= case token of\n\t\tForAllToken\n\t\t\t-> wantUniversalQuantifiedVariables pState \n\t\t_\t-> ([], tokenBack pState)\n\nwantUniversalQuantifiedVariables :: !*ParseState -> *(![ATypeVar],!*ParseState)\nwantUniversalQuantifiedVariables pState\n\t# (vars, pState) = wantList \"universal quantified variable(s)\" tryQuantifiedTypeVar pState\n\t= (vars, wantToken TypeContext \"Universal Quantified Variables\" ColonToken pState)\n\ntryQuantifiedTypeVar :: !ParseState -> (Bool, ATypeVar, ParseState)\ntryQuantifiedTypeVar pState\n\t# (token, pState)\t\t\t= nextToken TypeContext pState\n \t (succ, attr, pState)\t\t= try_attribute token pState\n \t| succ\n\t\t# (typevar, pState)\t= wantTypeVar pState\n\t\t (attr, pState)\t= adjustAttributeOfTypeVariable attr typevar.tv_ident pState\n\t\t= (True, {atv_attribute = attr, atv_variable = typevar}, pState)\n\t# (succ, typevar, pState) = tryTypeVarT token pState\n\t| succ\n\t\t= (True, {atv_attribute = TA_None, atv_variable = typevar}, pState)\n\t\t= (False, abort \"no ATypeVar\", pState)\nwhere\t\t\t\n\ttry_attribute DotToken pState = (True,\tTA_Anonymous,\tpState)\n\ttry_attribute AsteriskToken\tpState = (True,\tTA_Unique,\t\tpState)\n\ttry_attribute token \tpState = (False,\tTA_None,\tpState)\n\ntryATypeToType :: !AType !ParseState -> (!Bool, !Type, !ParseState)\ntryATypeToType atype pState\n\/*\t| atype.at_annotation <> AN_None\n\t\t= ( False\n\t\t , atype.at_type\n\t\t , parseError \"simple type\" No (\"type instead of type annotation \"+toString atype.at_annotation) pState\n\t\t )\n*\/\t| atype.at_attribute <> TA_None\n\t\t= ( False\n\t\t , atype.at_type\n\t\t , parseError \"simple type\" No (\"type instead of type attribute \"+toString atype.at_attribute) pState\n\t\t )\n\t\/\/ otherwise\n\t\t= (True, atype.at_type, pState)\n\n\/*\n\tExpressions\n*\/\ncIsAPattern\t\t:== True\ncIsNotAPattern\t:== False\n\nwantExpressionOrPattern :: !Bool !ParseState -> (!ParsedExpr, !ParseState)\nwantExpressionOrPattern is_pattern pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCharListToken charList \/\/ To produce a better error message\n\t\t\t->\tcharListError charList pState\n\t\t_\t| is_pattern\n\t\t\t\t->\twantPatternT token pState\n\t\t\t\t->\twantExpressionT token pState\n\nwantPattern :: !ParseState -> (!ParsedExpr, !ParseState)\nwantPattern pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCharListToken charList \/\/ To produce a better error message\n\t\t\t->\tcharListError charList pState\n\t\t_\n\t\t\t->\twantPatternT token pState\n\nwantExpression :: !ParseState -> (!ParsedExpr, !ParseState)\nwantExpression pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCharListToken charList \/\/ To produce a better error message\n\t\t\t->\tcharListError charList pState\n\t\t_\n\t\t\t->\twantExpressionT token pState\n\nwantPatternWithoutDefinitions :: !ParseState -> (!ParsedExpr, !ParseState)\nwantPatternWithoutDefinitions pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCharListToken charList \/\/ To produce a better error message\n\t\t\t->\tcharListError charList pState\n\t\t_\n\t\t\t->\twantPatternWithoutDefinitionsT token pState\n\ncharListError charList pState\n\t= (PE_Empty, parseError \"Expression\" No (\"List brackets, [ and ], around charlist '\"+charList+\"'\") pState)\n\nwantExpressionT :: !Token !ParseState -> (!ParsedExpr, !ParseState)\n\/\/ FIXME, case, let and if expression should also be recognised here\n\/\/ and not in trySimpleNonLhsExpressionT, for example\n\/\/ Start = id if True id id id 17\n\/\/ is currently allowed\nwantExpressionT DynamicToken pState\n\t# (dyn_expr, pState) = wantExpression pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == DoubleColonToken\n\t\t# (dyn_type, pState) = wantDynamicTypeInPattern\/*wantDynamicTypeInExpression*\/ pState\n\t\t= (PE_Dynamic dyn_expr (Yes dyn_type), pState)\n\t\t= (PE_Dynamic dyn_expr No, tokenBack pState)\nwantExpressionT token pState\n\t# (succ, expr, pState) = tryExtendedSimpleExpressionT token pState\n\t| succ\n\t\t# (exprs, pState) = parseList tryExtendedSimpleExpression pState\n\t\t= (combineExpressions expr exprs, pState)\n\t\t= case token of\n\t\t\tCharListToken charList\n\t\t\t\t-> (PE_Empty, parseError \"RHS expression\" No (\"List brackets, [ and ], around charlist '\"+charList+\"'\") pState)\n\t\t\t_\t-> (PE_Empty, parseError \"RHS expression\" (Yes token) \"\" pState)\n\nwantPatternT :: !Token !ParseState -> (!ParsedExpr, !ParseState)\nwantPatternT token pState\n\t# (exp, pState)\t= wantPatternT2 token pState\n\t# (token, pState)\t= nextToken FunctionContext pState\n\t| token == DoubleColonToken\n\t\t# (dyn_type, pState) = wantDynamicTypeInPattern pState\n\t\t= (PE_DynamicPattern exp dyn_type, pState)\n\t\t= (exp, tokenBack pState)\nwhere\n\twantPatternT2 :: !Token !ParseState -> (!ParsedExpr, !ParseState)\n\twantPatternT2 (IdentToken name) pState \/* to make a=:C x equivalent to a=:(C x) *\/\n\t\t| isLowerCaseName name\n\t\t\t# (id, pState)\t\t= stringToIdent name IC_Expression pState\n\t\t\t (token, pState)\t= nextToken FunctionContext pState\n\t\t\t| token == DefinesColonToken \n\t\t\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t\t\t= case token of\n\t\t\t\t\tIdentToken name\n\t\t\t\t\t\t| ~ (isLowerCaseName name)\n\t\t\t\t\t\t\t#\t(constructor, pState) = stringToIdent name IC_Expression pState\n\t\t\t\t\t\t\t\t(args, pState)\t= parseList trySimplePattern pState\n\t\t\t\t\t\t\t->\t(PE_Bound { bind_dst = id, bind_src = combineExpressions (PE_Ident constructor) args }, pState)\n\t\t\t\t\t_\t# (succ, expr, pState) = trySimplePatternT token pState\n\t\t\t\t\t\t| succ\n\t\t\t\t\t\t\t# expr1 = PE_Bound { bind_dst = id, bind_src = expr }\n\t\t\t\t\t\t\t# (exprs, pState) = parseList trySimplePattern pState\n\t\t\t\t\t\t\t->\t(combineExpressions expr1 exprs, pState)\n\t\t\t\t\t\t\/\/ not succ\n\t\t\t\t\t\t\t-> (PE_Empty, parseError \"LHS expression\" (Yes token) \"\" pState)\n\t\t\t| token == DoubleColonToken\n\t\t\t\t# (dyn_type, pState) = wantDynamicTypeInPattern pState\n\t\t\t\t= (PE_DynamicPattern (PE_Ident id) dyn_type, pState)\n\t\t\t\/\/ token <> DefinesColonToken \/\/ token back and call to wantPatternT2 would do also.\n\t\t\t# (exprs, pState) = parseList trySimplePattern (tokenBack pState)\n\t\t\t= (combineExpressions (PE_Ident id) exprs, pState)\n\twantPatternT2 token pState\n\t\t# (succ, expr, pState) = trySimplePatternT token pState\n\t\t| succ\n\t\t\t# (exprs, pState) = parseList trySimplePattern pState\n\t\t\t= (combineExpressions expr exprs, pState)\n\t\t\t= (PE_Empty, parseError \"LHS expression\" (Yes token) \"\" pState)\n\nwantPatternWithoutDefinitionsT :: !Token !ParseState -> (!ParsedExpr, !ParseState)\nwantPatternWithoutDefinitionsT token pState\n\t# (succ, expr, pState) = trySimplePatternWithoutDefinitionsT token pState\n\t| succ\n\t\t# (exprs, pState) = parseList trySimplePatternWithoutDefinitions pState\n\t\t= (combineExpressions expr exprs, pState)\n\t\t= (PE_Empty, parseError \"pattern\" (Yes token) \"\" pState)\n\ncombineExpressions expr []\n\t= expr\ncombineExpressions expr exprs\n\t= make_app_exp expr exprs\nwhere\n\tmake_app_exp exp []\n\t\t= exp\n\tmake_app_exp exp exprs\n\t\t= PE_List [exp : exprs]\n\ntrySimplePattern :: !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntrySimplePattern pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= trySimplePatternT token pState\n\ntrySimplePatternWithoutDefinitions :: !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntrySimplePatternWithoutDefinitions pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= trySimplePatternWithoutDefinitionsT token pState\n\ntryExtendedSimpleExpression :: !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntryExtendedSimpleExpression pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= tryExtendedSimpleExpressionT token pState\n\ntryExtendedSimpleExpressionT :: !Token !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntryExtendedSimpleExpressionT token pState\n\t# (succ, expr, pState) = trySimpleExpressionT token pState\n\t| succ\n\t\t# (expr, pState) = extend_expr_with_selectors expr pState\n\t\t= (True, expr, pState)\n\t\t= (False, PE_Empty, pState)\nwhere\n\textend_expr_with_selectors :: !ParsedExpr !ParseState -> (!ParsedExpr, !ParseState)\n\textend_expr_with_selectors exp pState \n \t\t# (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tDotToken\n\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t (selectors, token, pState) = wantSelectors token pState\n\t\t\t\t exp = PE_Selection ParsedNormalSelector exp selectors\n\t\t\t\t-> case token of\n\t\t\t\t\tDefinesColonToken\n\t\t\t\t\t\t-> parse_matches_expression exp pState\n\t\t\t\t\t_\n\t\t\t\t\t\t-> (exp, tokenBack pState)\n\t\t\tExclamationToken\n\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\/\/ JVG added for strict lists:\n\t\t\t\t| token==SquareCloseToken\n\t\t\t\t\t-> (exp, tokenBack (tokenBack pState))\n\/\/\t\t\t\n\t\t\t\t# (selectors, token, pState) = wantSelectors token pState\n\t\t\t\t exp = PE_Selection (ParsedUniqueSelector False) exp selectors\n\t\t\t\t-> case token of\n\t\t\t\t\tDefinesColonToken\n\t\t\t\t\t\t-> parse_matches_expression exp pState\n\t\t\t\t\t_\n\t\t\t\t\t\t-> (exp, tokenBack pState)\n\t\t\tDefinesColonToken\n\t\t\t\t-> parse_matches_expression exp pState\n\t\t\t_\n\t\t\t\t-> (exp, tokenBack pState)\n\n\tparse_matches_expression exp pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tIdentToken name\n\t\t\t\t| not (isLowerCaseName name)\n\t\t\t\t\t# (id, pState) = stringToIdent name IC_Expression pState\n\t\t\t\t\t (pattern_args,pState) = parse_wild_cards pState\n\t\t\t\t\t pattern = if (isEmpty pattern_args) (PE_Ident id) (PE_List [PE_Ident id:pattern_args])\n\t\t\t\t\t-> matches_expression exp pattern pState\n\t\t\t\/\/ to do: qualified ident\n\t\t\t_\n\t\t\t\t# (succ, pattern, pState) = trySimplePatternWithoutDefinitionsT token pState\n\t\t\t\t| succ\n\t\t\t\t\t-> matches_expression exp pattern pState\n\t\t\t\t\t# pState = parseError \"pattern\" (Yes token) \"\" pState\n\t\t\t\t\t-> matches_expression exp PE_Empty pState\n\n\tparse_wild_cards pState\n\t \t# (token, pState) = nextToken FunctionContext pState\n\t \t= case token of\n\t \t\tWildCardToken\n\t\t\t\t# (pattern_args,pState) = parse_wild_cards pState\n\t \t\t\t-> ([PE_WildCard:pattern_args],pState)\n\t \t\t_\n\t \t\t\t-> ([],tokenBack pState);\n\n\tmatches_expression exp pattern pState\n\t\t# (case_ident, pState) = internalIdent \"_c\" pState\n\t\t (fname,linenr,pState) = getFileAndLineNr pState\n\t\t position = LinePos fname linenr\n\t\t= (PE_Matches case_ident exp pattern position, pState)\n\nwantSelectors :: Token *ParseState -> *(![ParsedSelection], !Token, !*ParseState)\nwantSelectors token pState\n\t# (selector, pState) = want_selector token pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == DotToken\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t (selectors, token, pState) = wantSelectors token pState\n\t\t= (selector ++ selectors, token, pState)\n\t\t= (selector, token, pState)\nwhere\n\twant_selector :: !Token !*ParseState -> *(![ParsedSelection], !*ParseState)\n\twant_selector SquareOpenToken pState\n\t\t# (array_selectors, pState) = want_array_selectors pState\n\t\t= (array_selectors, wantToken FunctionContext \"array selector\" SquareCloseToken pState)\n\t\twhere\n\t\t\twant_array_selectors :: !*ParseState -> *(![ParsedSelection], !*ParseState)\n\t\t\twant_array_selectors pState\n\t \t\t\t# (index_expr, pState) = wantExpression pState\n\t\t\t\t selector = PS_Array index_expr\n\t \t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t\t| token == CommaToken\n\t\t\t\t\t# (selectors, pState) = want_array_selectors pState\n\t\t\t\t\t= ([selector : selectors], pState)\n\t\t\t\t\t= ([selector], tokenBack pState)\n\twant_selector (IdentToken name) pState\n\t\t| isUpperCaseName name\n\t\t\t# pState = wantToken FunctionContext \"record selector\" DotToken pState\n\t\t\t (type_id, pState) = stringToIdent name IC_Type pState\n\t\t\t= want_field_after_record_type (RecordNameIdent type_id) pState\n\t\t\t# (selector_id, pState) = stringToIdent name IC_Selector pState\n\t\t\t= ([PS_Record selector_id NoRecordName], pState)\n\twant_selector (QualifiedIdentToken module_name ident_name) pState\n\t\t| isUpperCaseName ident_name\n\t \t\t# pState = wantToken FunctionContext \"record selector\" DotToken pState\n\t \t\t (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Type pState\n\t\t\t= want_field_after_record_type (RecordNameQualifiedIdent module_id ident_name) pState\n\t\t\t# (module_id, pState) = stringToIdent module_name (IC_Module NoQualifiedIdents) pState\n\t\t\t= ([PS_QualifiedRecord module_id ident_name NoRecordName], pState)\n\twant_selector token pState\n\t\t= ([PS_Erroneous], parseError \"simple RHS expression\" (Yes token) \"\" pState)\n\n\twant_field_after_record_type record_name pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t= case token of\n\t\t\tIdentToken field_name\n\t\t\t\t| isLowerCaseName field_name\n\t\t\t\t\t# (selector_id, pState) = stringToIdent field_name IC_Selector pState\n\t\t\t\t\t-> ([PS_Record selector_id record_name], pState)\n\t\t\tQualifiedIdentToken module_name field_name\n\t\t\t\t| isLowerCaseName field_name\n\t\t\t\t\t# (module_id, pState) = stringToIdent module_name (IC_Module NoQualifiedIdents) pState\n\t\t\t\t\t-> ([PS_QualifiedRecord module_id field_name record_name], pState)\n\t\t\t_\n\t\t\t\t-> ([PS_Erroneous], parseError \"record field\" (Yes token) \"lower case ident\" pState)\n\ntrySimplePatternT :: !Token !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntrySimplePatternT (IdentToken name) pState\n\t# (id, pState) = stringToIdent name IC_Expression pState\n\t| isLowerCaseName name\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == DefinesColonToken\n\t\t\t# (succ, expr, pState) = trySimplePattern pState\n\t\t\t| succ\n\t\t\t\t= (True, PE_Bound { bind_dst = id, bind_src = expr }, pState)\n\t\t\t\t= (True, PE_Empty, parseError \"simple expression\" No \"expression\" pState)\n\t\t\t= (True, PE_Ident id, tokenBack pState)\n\t\t= (True, PE_Ident id, pState)\ntrySimplePatternT SquareOpenToken pState\n\t# (list_expr, pState) = wantListExp cIsAPattern pState\n\t= (True, list_expr, pState)\ntrySimplePatternT OpenToken pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCloseToken\n\t\t\t#! unit_cons_ident = predefined_idents.[PD_UnitConsSymbol]\n\t\t\t-> (True,PE_Ident unit_cons_ident,pState)\n\t\t_\n\t\t\t# (args=:[exp:exps], pState) = want_pattern_list_t token pState\n\t\t\t pState = wantToken FunctionContext \"pattern list\" CloseToken pState\n\t\t\t| isEmpty exps\n\t\t\t\t-> case exp of\n\t\t\t\t\tPE_Ident id\n\t\t\t\t\t\t-> (True, PE_List [exp], pState)\n\t\t\t\t\t_\n\t\t\t\t\t\t-> (True, exp, pState)\n\t\t\t\t-> (True, PE_Tuple args, pState)\nwhere\n\twant_pattern_list_t token pState\n\t\t# (expr, pState)\n\t\t\t= case token of\n\t\t\t\tCharListToken charList \/\/ To produce a better error message\n\t\t\t\t\t->\tcharListError charList pState\n\t\t\t\t_\n\t\t\t\t\t->\twantPatternT token pState\n\t\t= want_pattern_list_rest expr pState\n\n\twant_pattern_list pState\n\t\t# (expr, pState) = wantPattern pState\n\t\t= want_pattern_list_rest expr pState\n\n\twant_pattern_list_rest expr pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (exprs, pState) = want_pattern_list pState\n\t\t\t= ([expr : exprs], pState)\n\t\t\t= ([expr], tokenBack pState)\ntrySimplePatternT CurlyOpenToken pState\n\t# (rec_or_aray_exp, pState) = wantRecordOrArrayExp cIsAPattern pState \n\t= (True, rec_or_aray_exp, pState)\ntrySimplePatternT (IntToken int_string) pState\n\t# (ok,int) = string_to_int int_string\n\t| ok\n\t\t= (True, PE_Basic (BVInt int), pState)\n\t\t= (True, PE_Basic (BVI int_string), pState)\ntrySimplePatternT (StringToken string) pState\n\t= (True, PE_Basic (BVS string), pState)\ntrySimplePatternT (BoolToken bool) pState\n\t= (True, PE_Basic (BVB bool), pState)\ntrySimplePatternT (CharToken char) pState\n\t= (True, PE_Basic (BVC char), pState)\ntrySimplePatternT (RealToken real) pState\n\t= (True, PE_Basic (BVR real), pState)\ntrySimplePatternT (QualifiedIdentToken module_name ident_name) pState\n\t| not (isLowerCaseName ident_name)\n\t\t# (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Expression pState\n\t\t= (True, PE_QualifiedIdent module_id ident_name, pState)\ntrySimplePatternT WildCardToken pState\n\t= (True, PE_WildCard, pState)\ntrySimplePatternT token pState\n\t= (False, PE_Empty, tokenBack pState)\n\ntrySimplePatternWithoutDefinitionsT :: !Token !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntrySimplePatternWithoutDefinitionsT (IdentToken name) pState\n\t| not (isLowerCaseName name)\n\t\t# (id, pState) = stringToIdent name IC_Expression pState\n\t\t= (True, PE_Ident id, pState)\ntrySimplePatternWithoutDefinitionsT SquareOpenToken pState\n\t# (list_expr, pState) = wantListPatternWithoutDefinitions pState\n\t= (True, list_expr, pState)\ntrySimplePatternWithoutDefinitionsT OpenToken pState\n\t# (args=:[exp:exps], pState) = want_pattern_list pState\n\t pState = wantToken FunctionContext \"pattern list\" CloseToken pState\n\t| isEmpty exps\n\t\t= case exp of\n\t\t\tPE_Ident id\n\t\t\t\t-> (True, PE_List [exp], pState)\n\t\t\t_\n\t\t\t\t-> (True, exp, pState)\n\t\t= (True, PE_Tuple args, pState)\nwhere\n\twant_pattern_list pState\n\t\t# (expr, pState) = wantPatternWithoutDefinitions pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (exprs, pState) = want_pattern_list pState\n\t\t\t= ([expr : exprs], pState)\n\t\t\t= ([expr], tokenBack pState)\ntrySimplePatternWithoutDefinitionsT CurlyOpenToken pState\n\t# (rec_or_aray_exp, pState) = wantRecordPatternWithoutDefinitions pState \n\t= (True, rec_or_aray_exp, pState)\ntrySimplePatternWithoutDefinitionsT (IntToken int_string) pState\n\t# (ok,int) = string_to_int int_string\n\t| ok\n\t\t= (True, PE_Basic (BVInt int), pState)\n\t\t= (True, PE_Basic (BVI int_string), pState)\ntrySimplePatternWithoutDefinitionsT (StringToken string) pState\n\t= (True, PE_Basic (BVS string), pState)\ntrySimplePatternWithoutDefinitionsT (BoolToken bool) pState\n\t= (True, PE_Basic (BVB bool), pState)\ntrySimplePatternWithoutDefinitionsT (CharToken char) pState\n\t= (True, PE_Basic (BVC char), pState)\ntrySimplePatternWithoutDefinitionsT (RealToken real) pState\n\t= (True, PE_Basic (BVR real), pState)\ntrySimplePatternWithoutDefinitionsT (QualifiedIdentToken module_name ident_name) pState\n\t| not (isLowerCaseName ident_name)\n\t\t# (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Expression pState\n\t\t= (True, PE_QualifiedIdent module_id ident_name, pState)\ntrySimplePatternWithoutDefinitionsT WildCardToken pState\n\t= (True, PE_WildCard, pState)\ntrySimplePatternWithoutDefinitionsT token pState\n\t= (False, PE_Empty, tokenBack pState)\n\ntrySimpleExpressionT :: !Token !ParseState -> (!Bool, !ParsedExpr, !ParseState)\ntrySimpleExpressionT (IdentToken name) pState\n\t# (id, pState) = stringToIdent name IC_Expression pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == GenericOpenToken\n\t\t# (kind, pState) = wantKind pState\t\n\t\t= (True, PE_Generic id kind, pState)\n\t\t= (True, PE_Ident id, tokenBack pState)\ntrySimpleExpressionT SquareOpenToken pState\n\t# (list_expr, pState) = wantListExp cIsNotAPattern pState\n\t= (True, list_expr, pState)\ntrySimpleExpressionT OpenToken pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= case token of\n\t\tCloseToken\n\t\t\t#! unit_cons_ident = predefined_idents.[PD_UnitConsSymbol]\n\t\t\t-> (True,PE_Ident unit_cons_ident,pState)\n\t\t_\n\t\t\t# (args=:[exp:exps], pState) = want_expression_list_t token pState\n\t\t\t pState = wantToken FunctionContext \"expression list\" CloseToken pState\n\t\t\t| isEmpty exps\n\t\t\t\t-> case exp of\n\t\t\t\t\tPE_Ident id\n\t\t\t\t\t\t-> (True, PE_List [exp], pState)\n\t\t\t\t\t_\n\t\t\t\t\t\t-> (True, exp, pState)\n\t\t\t\t-> (True, PE_Tuple args, pState)\nwhere\n\twant_expression_list_t token pState\n\t\t# (expr, pState)\n\t\t\t= case token of\n\t\t\t\tCharListToken charList\n\t\t\t\t\t \/\/ To produce a better error message\n\t\t\t\t\t->\tcharListError charList pState\n\t\t\t\t_\n\t\t\t\t\t-> wantExpressionT token pState\n\t\t= want_expression_list_rest expr pState\n\n\twant_expression_list pState\n\t\t# (expr, pState) = wantExpression pState\n\t\t= want_expression_list_rest expr pState\n\n\twant_expression_list_rest expr pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (exprs, pState) = want_expression_list pState\n\t\t\t= ([expr : exprs], pState)\n\t\t\t= ([expr], tokenBack pState)\ntrySimpleExpressionT CurlyOpenToken pState\n\t# (rec_or_aray_exp, pState) = wantRecordOrArrayExp cIsNotAPattern pState \n\t= (True, rec_or_aray_exp, pState)\ntrySimpleExpressionT (IntToken int_string) pState\n\t# (ok,int) = string_to_int int_string\n\t| ok\n\t\t= (True, PE_Basic (BVInt int), pState)\n\t\t= (True, PE_Basic (BVI int_string), pState)\ntrySimpleExpressionT (StringToken string) pState\n\t= (True, PE_Basic (BVS string), pState)\ntrySimpleExpressionT (BoolToken bool) pState\n\t= (True, PE_Basic (BVB bool), pState)\ntrySimpleExpressionT (CharToken char) pState\n\t= (True, PE_Basic (BVC char), pState)\ntrySimpleExpressionT (RealToken real) pState\n\t= (True, PE_Basic (BVR real), pState)\ntrySimpleExpressionT (QualifiedIdentToken module_name ident_name) pState\n\t# (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Expression pState\n\t= (True, PE_QualifiedIdent module_id ident_name, pState)\ntrySimpleExpressionT token pState\n\t= trySimpleNonLhsExpressionT token pState\n\nstring_to_int s\n\t| len==0\n\t\t= (False,0)\n\t| s.[0] == '-'\n\t\t| len>2 && s.[1]=='0' \/* octal *\/\n\t\t\t= (False,0)\n\t\t\t# (ok,int) = (string_to_int2 1 0 s)\n\t\t\t=\t(ok,~int)\n\t| s.[0] == '+'\n\t\t| len>2&& s.[1]=='0' \/* octal *\/\n\t\t\t= (False,0)\n\t\t\t=\tstring_to_int2 1 0 s\n\t| s.[0]=='0' && len>1 \/* octal *\/\n\t\t= (False,0)\n\t\t=\tstring_to_int2 0 0 s\n where\n\tlen = size s\n\n\tstring_to_int2:: !Int !Int !{#Char} -> (!Bool,!Int)\n\tstring_to_int2 posn val s\n\t\t| len==posn\n\t\t\t= (True,val)\n\t\t# n =\ttoInt (s.[posn]) - toInt '0'\n\t\t|\t0<=n && n<= 9\n\t\t\t=\tstring_to_int2 (posn+1) (n+val*10) s\n\t\t\t=\t(False,0)\n\ntrySimpleNonLhsExpressionT :: !Token *ParseState -> *(!Bool,!ParsedExpr,!*ParseState)\ntrySimpleNonLhsExpressionT BackSlashToken pState\n\t# (lam_ident, pState)\t= internalIdent (toString backslash) pState\n\t (file_name, line_nr, pState)\n\t \t\t\t\t\t\t= getFileAndLineNr pState\n\t position\t\t\t\t= FunPos file_name line_nr lam_ident.id_name\n\t (lam_args, pState) \t= wantList \"arguments\" trySimplePattern pState\n\t (token, pState)\t\t= nextToken FunctionContext pState\n\t= case token of\n\t\tDotToken\n\t\t\t# (file_name, line_nr, pState) = getFileAndLineNr pState\n\t\t\t (expr, pState) = wantExpression pState\n\t\t\t ewl = {ewl_nodes = [], ewl_expr = expr, ewl_locals = LocalParsedDefs [], ewl_position = LinePos file_name line_nr}\n\t\t\t rhs = {rhs_alts = UnGuardedExpr ewl, rhs_locals = LocalParsedDefs []}\n\t\t\t-> (True, PE_Lambda lam_ident lam_args rhs position, pState)\n\t\t_\n\t\t \t# (rhs, defining_symbol, pState)\n\t\t\t \t\t\t\t\t\t= wantRhs_without_where token True RhsDefiningSymbolCase pState\n\t\t\t-> (True, PE_Lambda lam_ident lam_args rhs position, pState)\ntrySimpleNonLhsExpressionT (LetToken strict) pState \/\/ let! is not supported in Clean 2.0\n\t| strict\t\t\t\t= (False, PE_Empty, parseError \"Expression\" No \"let! (strict let) not supported in this version of Clean, expression\" pState)\n\t\/\/ otherwise\n\t# (let_binds, pState)\t= wantLocals pState\n\t pState\t\t\t\t= wantToken FunctionContext \"let expression\" InToken pState\n\t (let_expr, pState)\t= wantExpression pState\n\t= (True, PE_Let let_binds let_expr, pState)\ntrySimpleNonLhsExpressionT CaseToken pState\n \t# (case_exp, pState)\t\t= wantCaseExp pState\n\t= (True, case_exp, pState)\ntrySimpleNonLhsExpressionT IfToken pState\n\t# (if_ident, pState) \t\t= internalIdent \"_if\" pState\n \t (cond_exp, pState)\t\t= want_simple_expression \"condition of if\" pState\n \t (then_exp, pState)\t\t= want_simple_expression \"then-part of if\" pState\n \t (else_exp, pState)\t\t= want_simple_expression \"else-part of if\" pState\n\t= (True, PE_If if_ident cond_exp then_exp else_exp, pState)\nwhere\n\twant_simple_expression error pState\n\t\t# (succ, expr, pState) = tryExtendedSimpleExpression pState\n\t\t| succ\n\t\t\t= (expr, pState)\n\t\t\t= (PE_Empty, parseError error No \"\" pState)\ntrySimpleNonLhsExpressionT token pState\n\t= (False, PE_Empty, tokenBack pState)\n\nwantListPatternWithoutDefinitions :: !ParseState -> (ParsedExpr, !ParseState)\nwantListPatternWithoutDefinitions pState\n\t# pState=appScanState setNoNewOffsideForSeqLetBit pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t# pState=appScanState clearNoNewOffsideForSeqLetBit pState\t\n\t# (head_strictness,token,pState) = want_head_strictness token pState\n\t| token==ExclamationToken && (head_strictness<>HeadOverloaded && head_strictness<>HeadUnboxedAndTailStrict)\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token==SquareCloseToken\n\t\t\t= (makeTailStrictNilExpression head_strictness cIsAPattern,pState)\n\t\t\t= (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t| token==SquareCloseToken\n\t\t| head_strictness==HeadUnboxedAndTailStrict\n\t\t\t= (makeTailStrictNilExpression HeadUnboxed cIsAPattern,pState)\n\t\t| head_strictness==HeadStrict\n\t\t\t# (tail_strict,pState) = is_tail_strict_list_or_nil pState\n\t\t\t| tail_strict\n\t\t\t\t= (makeTailStrictNilExpression HeadLazy cIsAPattern,pState)\n\t\t\t\t= (makeNilExpression head_strictness cIsAPattern,pState)\n\t\t\t= (makeNilExpression head_strictness cIsAPattern,pState)\n\t| head_strictness==HeadUnboxedAndTailStrict\n\t\t= (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t| head_strictness==HeadLazy && (case token of (IdentToken \"!!\") -> True; _ -> False)\n\t\t# (next_token,pState) = nextToken FunctionContext pState\n\t\t| next_token==SquareCloseToken\n\t\t\t= (makeTailStrictNilExpression HeadStrict cIsAPattern,pState)\n\t\t\t= want_LGraphExpr token [] head_strictness (tokenBack pState)\n\t\t= want_LGraphExpr token [] head_strictness pState\n\twhere\n\t\twant_LGraphExpr token acc head_strictness pState\n\t\t\t= case token of\n\t\t\t\tCharListToken chars\n\t\t\t\t\t->\twant_list (add_chars (fromString chars) acc) pState\n\t\t\t\t_\t#\t(exp, pState) = wantPatternWithoutDefinitionsT token pState\n\t\t\t\t\t->\twant_list [exp: acc] pState\n\t\twhere\n\t\t\twant_list acc pState\n\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t= case token of\n\t\t\t\t\tSquareCloseToken\n\t\t\t\t\t\t#\tnil_expr = makeNilExpression head_strictness cIsAPattern\n\t\t\t\t\t\t->\t(gen_pattern_cons_nodes acc nil_expr head_strictness,pState)\n\t\t\t\t\tExclamationToken\n\t\t\t\t\t\t| head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t| token==SquareCloseToken\n\t\t\t\t\t\t\t\t# nil_expr = makeTailStrictNilExpression head_strictness cIsAPattern\n\t\t\t\t\t\t\t\t->\t(gen_pattern_tail_strict_cons_nodes acc nil_expr head_strictness,pState)\n\t\t\t\t\t\t\t\t-> (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t\t\t\t\tCommaToken\n\t\t\t\t\t\t#\t(token, pState)\t= nextToken FunctionContext pState\n\t\t\t\t\t\t->\twant_LGraphExpr token acc head_strictness pState\n\t\t\t\t\tColonToken\n\t\t\t\t\t\t# (exp, pState)\t\t= wantPatternWithoutDefinitions pState\n\t\t\t\t\t\t# (token,pState)\t= nextToken FunctionContext pState\n\t\t\t\t\t\t| token==SquareCloseToken\n\t\t\t\t\t\t\t-> (gen_pattern_cons_nodes acc exp head_strictness,pState)\n\t\t\t\t\t\t| token==ExclamationToken && head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t# pState = wantToken FunctionContext \"list\" SquareCloseToken pState\n\t\t\t\t\t\t\t-> (gen_pattern_tail_strict_cons_nodes acc exp head_strictness,pState)\n\t\t\t\t\t\t| token==ColonToken \/\/ to allow [1:2:[]] etc.\n\t\t\t\t\t\t\t-> want_list [exp:acc] (tokenBack pState)\n\t\t\t\t\t\t\t# pState = parseError \"list\" (Yes token) \"] or :\" pState\n\t\t\t\t\t\t\t-> (gen_pattern_cons_nodes acc exp head_strictness,pState)\n\t\t\t\t\tDotDotToken\n\t\t\t\t\t\t->\t(PE_Empty, parseError \"want list expression\" No \"No dot dot expression in a pattern\" pState)\n\t\t\t\t\tDoubleBackSlashToken\n\t\t\t\t\t\t->\t(PE_Empty, parseError \"want list expression\" No \"No \\\\\\\\ expression in a pattern\" pState)\n\t\t\t\t\t_\n\t\t\t\t\t\t#\tnil_expr = makeNilExpression head_strictness cIsAPattern\n\t\t\t\t\t\t\tpState\t= parseError \"list\" (Yes token) \"list element separator\" pState\n\t\t\t\t\t\t->\t(gen_pattern_cons_nodes acc nil_expr head_strictness,pState)\n\ngen_pattern_cons_nodes [] exp head_strictness\n\t= exp\ngen_pattern_cons_nodes l exp head_strictness\n\t= gen_pattern_cons_nodes l exp\nwhere\n\tcons_ident_exp = makeConsIdentExpression head_strictness cIsAPattern\n\t\n\tgen_pattern_cons_nodes [e:r] exp\n\t\t= gen_pattern_cons_nodes r (PE_List [cons_ident_exp,e,exp])\n\tgen_pattern_cons_nodes [] exp\n\t\t= exp\n\ngen_pattern_tail_strict_cons_nodes [] exp head_strictness\n\t= exp\ngen_pattern_tail_strict_cons_nodes r exp head_strictness\n\t= gen_pattern_tail_strict_cons_nodes r exp\nwhere\n\ttail_strict_cons_ident_exp = makeTailStrictConsIdentExpression head_strictness cIsAPattern\n\t\n\tgen_pattern_tail_strict_cons_nodes [e:r] exp\n\t\t= gen_pattern_tail_strict_cons_nodes r (PE_List [tail_strict_cons_ident_exp,e,exp])\n\tgen_pattern_tail_strict_cons_nodes [] exp\n\t\t= exp\n\nwantListExp :: !Bool !ParseState -> (ParsedExpr, !ParseState)\nwantListExp is_pattern pState\n\t# pState=appScanState setNoNewOffsideForSeqLetBit pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t# pState=appScanState clearNoNewOffsideForSeqLetBit pState\t\n\t# (head_strictness,token,pState) = want_head_strictness token pState\n\t| token==ExclamationToken && (head_strictness<>HeadOverloaded && head_strictness<>HeadUnboxedAndTailStrict)\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token==SquareCloseToken\n\t\t\t= (makeTailStrictNilExpression head_strictness is_pattern,pState)\n\t\t\t= (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t| token==SquareCloseToken\n\t\t| head_strictness==HeadUnboxedAndTailStrict\n\t\t\t= (makeTailStrictNilExpression HeadUnboxed is_pattern,pState)\n\t\t| head_strictness==HeadStrict\n\t\t\t# (tail_strict,pState) = is_tail_strict_list_or_nil pState\n\t\t\t| tail_strict\n\t\t\t\t= (makeTailStrictNilExpression HeadLazy is_pattern,pState)\n\t\t\t\t= (makeNilExpression head_strictness is_pattern,pState)\n\t\t\t= (makeNilExpression head_strictness is_pattern,pState)\n\t| head_strictness==HeadUnboxedAndTailStrict\n\t\t= (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t| head_strictness==HeadLazy && (case token of (IdentToken \"!!\") -> True; _ -> False)\n\t\t# (next_token,pState) = nextToken FunctionContext pState\n\t\t| next_token==SquareCloseToken\n\t\t\t= (makeTailStrictNilExpression HeadStrict is_pattern,pState)\n\t\t\t= want_LGraphExpr token [] head_strictness (tokenBack pState)\n\t\t= want_LGraphExpr token [] head_strictness pState\n\twhere\n\t\twant_LGraphExpr token acc head_strictness pState\n\t\t\t= case token of\n\t\t\t\tCharListToken chars\n\t\t\t\t\t->\twant_list (add_chars (fromString chars) acc) pState\n\t\t\t\t_\t#\t(exp, pState) = (if is_pattern (wantPatternT token) (wantExpressionT token)) pState\n\t\t\t\t\t->\twant_list [exp: acc] pState\n\t\twhere\n\t\t\twant_list acc pState\n\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t= case token of\n\t\t\t\t\tSquareCloseToken\n\t\t\t\t\t\t#\tnil_expr = makeNilExpression head_strictness is_pattern\n\t\t\t\t\t\t->\t(gen_cons_nodes acc nil_expr,pState)\n\t\t\t\t\tExclamationToken\n\t\t\t\t\t\t| head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t| token==SquareCloseToken\n\t\t\t\t\t\t\t\t# nil_expr = makeTailStrictNilExpression head_strictness is_pattern\n\t\t\t\t\t\t\t\t->\t(gen_tail_strict_cons_nodes acc nil_expr,pState)\n\t\t\t\t\t\t\t\t-> (PE_Empty,parseError \"list\" (Yes token) (toString SquareCloseToken) pState)\n\t\t\t\t\tCommaToken\n\t\t\t\t\t\t#\t(token, pState)\t= nextToken FunctionContext pState\n\t\t\t\t\t\t->\twant_LGraphExpr token acc head_strictness pState\n\t\t\t\t\tColonToken\n\t\t\t\t\t\t# (exp, pState)\t\t= wantExpressionOrPattern is_pattern pState\n\t\t\t\t\t\t# (token,pState)\t= nextToken FunctionContext pState\n\t\t\t\t\t\t| token==SquareCloseToken\n\t\t\t\t\t\t\t-> (gen_cons_nodes acc exp,pState)\n\t\t\t\t\t\t| token==ExclamationToken && head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t# pState = wantToken FunctionContext \"list\" SquareCloseToken pState\n\t\t\t\t\t\t\t-> (gen_tail_strict_cons_nodes acc exp,pState)\n\t\t\t\t\t\t| token==ColonToken \/\/ to allow [1:2:[]] etc.\n\t\t\t\t\t\t\t-> want_list [exp:acc] (tokenBack pState)\n\t\t\t\t\t\t\t# pState = parseError \"list\" (Yes token) \"] or :\" pState\n\t\t\t\t\t\t\t-> (gen_cons_nodes acc exp,pState)\n\t\t\t\t\tDotDotToken\n\t\t\t\t\t\t| is_pattern\n\t\t\t\t\t\t->\t(PE_Empty, parseError \"want list expression\" No \"No dot dot expression in a pattern\" pState)\n\t\t\t\t\t\t| length acc > 2 || isEmpty acc\n\t\t\t\t\t\t#\tnil_expr = makeNilExpression head_strictness is_pattern\n\t\t\t\t\t\t\tpState\t\t\t\t= parseError \"list expression\" No \"one or two expressions before ..\" pState\n\t\t\t\t\t\t->\t(gen_cons_nodes acc nil_expr,pState)\n\t\t\t\t\t\t#\t(token, pState)\t\t= nextToken FunctionContext pState\n\t\t\t\t\t\t->\tcase token of\n\t\t\t\t\t\t\t SquareCloseToken\n\t\t\t\t\t\t\t\t->\tcase acc of\n\t\t\t\t\t\t\t\t\t\t[e]\n\t\t\t\t\t\t\t\t\t\t\t# pd_from_index =\n\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromS\n\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromU\n\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadOverloaded) PD_FromO\n\t\t\t\t\t\t\t\t\t\t\t\t\tPD_From))\n\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_From pd_from_index e), pState)\n\t\t\t\t\t\t\t\t\t\t[e2,e1]\n\t\t\t\t\t\t\t\t\t\t\t# pd_from_then_index =\n\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromThenS\n\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromThenU\n\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadOverloaded) PD_FromThenO\n\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromThen))\n\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromThen pd_from_then_index e1 e2), pState)\n\t\t\t\t\t\t\t\t\t\t_\t-> abort \"Error 1 in WantListExp\"\n\t\t\t\t\t\t\t ExclamationToken\n\t\t\t\t\t\t\t\t| head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t\t\t# pState = wantToken FunctionContext \"dot dot expression\" SquareCloseToken pState\n\t\t\t\t\t\t\t\t\t->\tcase acc of\n\t\t\t\t\t\t\t\t\t\t\t[e]\n\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromSTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromUTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromTS)\n\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_From pd_from_index e), pState)\n\t\t\t\t\t\t\t\t\t\t\t[e2,e1]\n\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_then_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromThenSTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromThenUTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromThenTS)\n\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromThen pd_from_then_index e1 e2), pState)\n\t\t\t\t\t\t\t\t\t\t\t_\t-> abort \"Error 2 in WantListExp\"\n\t\t\t\t\t\t\t _\t#\t(exp, pState)\t= wantExpressionT token pState\n\t\t\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t\t-> case token of\n\t\t\t\t\t\t\t\t\tSquareCloseToken\n\t\t\t\t\t\t\t\t\t\t->\tcase acc of\n\t\t\t\t\t\t\t\t\t\t\t[e]\n\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_to_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromToS\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromToU\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadOverloaded) PD_FromToO\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromTo))\n\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromTo pd_from_to_index e exp), pState)\n\t\t\t\t\t\t\t\t\t\t\t[e2,e1]\n\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_then_to_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromThenToS\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromThenToU\n\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadOverloaded) PD_FromThenToO\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromThenTo))\n\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromThenTo pd_from_then_to_index e1 e2 exp), pState)\n\t\t\t\t\t\t\t\t\t\t\t_\t-> abort \"Error 3 in WantListExp\"\n\t\t\t\t\t\t\t\t\tExclamationToken\n\t\t\t\t\t\t\t\t\t\t| head_strictness<>HeadOverloaded\n\t\t\t\t\t\t\t\t\t\t\t# pState = wantToken FunctionContext \"dot dot expression\" SquareCloseToken pState\n\t\t\t\t\t\t\t\t\t\t\t->\tcase acc of\n\t\t\t\t\t\t\t\t\t\t\t\t\t[e]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_to_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromToSTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromToUTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromToTS)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromTo pd_from_to_index e exp), pState)\n\t\t\t\t\t\t\t\t\t\t\t\t\t[e2,e1]\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t# pd_from_then_to_index =\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (head_strictness==HeadStrict) PD_FromThenToSTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(if (head_strictness==HeadUnboxed) PD_FromThenToUTS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tPD_FromThenToTS)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t-> (PE_Sequ (SQ_FromThenTo pd_from_then_to_index e1 e2 exp), pState)\n\t\t\t\t\t\t\t\t\t\t\t\t\t_\t-> abort \"Error 4 in WantListExp\"\n\t\t\t\t\t\t\t\t\t_\n\t\t\t\t\t\t\t\t\t\t-> (PE_Empty, parseError \"dot dot expression\" (Yes token) \"] or !]\" pState)\n\t\t\t\t\tDoubleBackSlashToken\n\t\t\t\t\t\t| is_pattern\n\t\t\t\t\t\t->\t(PE_Empty, parseError \"want list expression\" No \"No \\\\\\\\ expression in a pattern\" pState)\n\t\t\t\t\t\t| length acc == 1\n\t\t\t\t\t\t->\twantListComprehension head_strictness (acc!!0) pState\n\t\t\t\t\t\t\/\/ otherwise \/\/ length acc <> 1\n\t\t\t\t\t\t#\tnil_expr = makeNilExpression head_strictness is_pattern\n\t\t\t\t\t\t\tpState\t\t\t\t= parseError \"list comprehension\" No \"one expressions before \\\\\\\\\" pState\n\t\t\t\t\t\t->\t(gen_cons_nodes acc nil_expr,pState)\n\t\t\t\t\t_\t#\tnil_expr = makeNilExpression head_strictness is_pattern\n\t\t\t\t\t\t\tpState\t= parseError \"list\" (Yes token) \"list element separator\" pState\n\t\t\t\t\t\t->\t(gen_cons_nodes acc nil_expr,pState)\n\t\t\t\n\t\t\tgen_cons_nodes [] exp\n\t\t\t\t= exp\n\t\t\tgen_cons_nodes l exp\n\t\t\t\t= gen_cons_nodes l exp\n\t\t\twhere\n\t\t\t\tcons_ident_exp = makeConsIdentExpression head_strictness is_pattern\n\t\t\t\t\n\t\t\t\tgen_cons_nodes [e:r] exp\n\t\t\t\t\t= gen_cons_nodes r (PE_List [cons_ident_exp,e,exp])\n\t\t\t\tgen_cons_nodes [] exp\n\t\t\t\t\t= exp\n\n\t\t\tgen_tail_strict_cons_nodes [] exp\n\t\t\t\t= exp\n\t\t\tgen_tail_strict_cons_nodes r exp\n\t\t\t\t= gen_tail_strict_cons_nodes r exp\n\t\t\twhere\n\t\t\t\ttail_strict_cons_ident_exp = makeTailStrictConsIdentExpression head_strictness is_pattern\n\t\t\t\t\n\t\t\t\tgen_tail_strict_cons_nodes [e:r] exp\n\t\t\t\t\t= gen_tail_strict_cons_nodes r (PE_List [tail_strict_cons_ident_exp,e,exp])\n\t\t\t\tgen_tail_strict_cons_nodes [] exp\n\t\t\t\t\t= exp\n\nwant_head_strictness :: Token *ParseState -> *(!Int,!Token,!*ParseState)\nwant_head_strictness ExclamationToken pState\n\t# (token,pState) = nextToken FunctionContext pState\n\t= (HeadStrict,token,pState)\nwant_head_strictness (SeqLetToken strict) pState\n\t# (token,pState) = nextToken FunctionContext pState\n\t| strict\n\t\t= (HeadUnboxedAndTailStrict,token,pState);\n\t\t= (HeadUnboxed,token,pState)\nwant_head_strictness BarToken pState\n\t# (token,pState) = nextToken FunctionContext pState\n\t= (HeadOverloaded,token,pState)\nwant_head_strictness token pState\n\t= (HeadLazy,token,pState)\n\nadd_chars [] \t\t\tacc\t= acc\nadd_chars ['\\\\',c1,c2,c3:r] acc\n\t| c1>='0' && c1<='7'\n\t\t= add_chars r [PE_Basic (BVC (toString ['\\'','\\\\',c1,c2,c3,'\\''])): acc]\nadd_chars ['\\\\',c:r] acc = add_chars r [PE_Basic (BVC (toString ['\\'','\\\\',c,'\\''])): acc]\nadd_chars [c:r] \t\tacc\t= add_chars r [PE_Basic (BVC (toString ['\\'',c,'\\''])): acc]\n\nmakeNilExpression :: Int Bool -> ParsedExpr\nmakeNilExpression head_strictness is_pattern\n\t# pre_def_nil_index= if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_NilSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictNilSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadOverloaded)\n\t\t\t\t\t\t\t(if is_pattern PD_OverloadedNilSymbol PD_nil)\n\t\t\t\t\t\t\t(if is_pattern PD_UnboxedNilSymbol PD_nil_u)))\n\t#! nil_ident = predefined_idents.[pre_def_nil_index]\n\t= PE_Ident nil_ident\n\nmakeTailStrictNilExpression :: Int Bool -> ParsedExpr\nmakeTailStrictNilExpression head_strictness is_pattern\n\t# pre_def_nil_index= if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_TailStrictNilSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictTailStrictNilSymbol\n\t\t\t\t\t\t\t(if is_pattern PD_UnboxedTailStrictNilSymbol PD_nil_uts))\n\t#! nil_ident = predefined_idents.[pre_def_nil_index]\n\t= PE_Ident nil_ident\n\nmakeConsIdentExpression :: Int Bool -> ParsedExpr\nmakeConsIdentExpression head_strictness is_pattern\n\t# pre_def_cons_index=if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_ConsSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictConsSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadOverloaded)\n\t\t\t\t\t\t\t(if is_pattern PD_OverloadedConsSymbol PD_cons)\n\t\t\t\t\t\t\t(if is_pattern PD_UnboxedConsSymbol PD_cons_u)))\n\t#! cons_ident = predefined_idents.[pre_def_cons_index]\n\t= PE_Ident cons_ident\n\ncons_and_nil_symbol_index HeadLazy = (PD_ConsSymbol,PD_NilSymbol)\ncons_and_nil_symbol_index HeadStrict = (PD_StrictConsSymbol,PD_StrictNilSymbol)\ncons_and_nil_symbol_index HeadUnboxed = (PD_cons_u,PD_nil_u)\ncons_and_nil_symbol_index HeadOverloaded = (PD_cons,PD_nil)\n\nmakeTailStrictConsIdentExpression :: Int Bool -> ParsedExpr\nmakeTailStrictConsIdentExpression head_strictness is_pattern\n\t# pre_def_cons_index=if (head_strictness==HeadLazy)\n\t\t\t\t\t\t\tPD_TailStrictConsSymbol\n\t\t\t\t\t\t(if (head_strictness==HeadStrict)\n\t\t\t\t\t\t\tPD_StrictTailStrictConsSymbol\n\t\t\t\t\t\t\t(if is_pattern PD_UnboxedTailStrictConsSymbol PD_cons_uts))\n\t#! cons_ident = predefined_idents.[pre_def_cons_index]\n\t= PE_Ident cons_ident\n\ntail_strict_cons_and_nil_symbol_index HeadLazy = (PD_TailStrictConsSymbol,PD_TailStrictNilSymbol)\ntail_strict_cons_and_nil_symbol_index HeadStrict = (PD_StrictTailStrictConsSymbol,PD_StrictTailStrictNilSymbol)\ntail_strict_cons_and_nil_symbol_index HeadUnboxed = (PD_cons_uts,PD_nil_uts)\n\n\/*\n\t(List and Array) Comprehensions\n*\/\n\nwantArrayComprehension :: !ArrayKind !ParsedExpr !ParseState -> (!ParsedExpr, !ParseState)\nwantArrayComprehension array_kind exp pState\n\t# (qualifiers, pState) = wantQualifiers pState\n\t= (PE_ArrayCompr array_kind exp qualifiers, wantToken FunctionContext \"array comprehension\" CurlyCloseToken pState)\n\nwantListComprehension :: !Int !ParsedExpr !ParseState -> (!ParsedExpr, !ParseState)\nwantListComprehension head_strictness exp pState\n\t# (qualifiers, pState) = wantQualifiers pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token==SquareCloseToken\n\t\t# (cons_index,nil_index) = cons_and_nil_symbol_index head_strictness\n\t\t= (PE_ListCompr cons_index nil_index exp qualifiers, pState)\n\t| token==ExclamationToken && head_strictness<>HeadOverloaded\n\t\t# pState = wantToken FunctionContext \"list comprehension\" SquareCloseToken pState\n\t\t# (tail_strict_cons_index,tail_strict_nil_index) = tail_strict_cons_and_nil_symbol_index head_strictness\n\t\t= (PE_ListCompr tail_strict_cons_index tail_strict_nil_index exp qualifiers, pState)\n\t\t# pState = parseError \"list\" (Yes token) (toString SquareCloseToken) pState\n\t\t# (cons_index,nil_index) = cons_and_nil_symbol_index head_strictness\n\t\t= (PE_ListCompr cons_index nil_index exp qualifiers, pState)\n\nwantQualifiers :: !ParseState -> (![Qualifier], !ParseState)\nwantQualifiers pState\n\t# (qual, pState) = want_qualifier pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == CommaToken\n\t\t# (quals, pState) = wantQualifiers pState\n\t\t= ([qual : quals], pState)\n\t\t= ([qual], tokenBack pState)\nwhere\n\twant_qualifier :: !ParseState -> (!Qualifier, !ParseState)\n\twant_qualifier pState\n\t\t# (qual_position, pState) = getPosition pState\n\t\t (qual_filename, pState) = accScanState getFilename pState\n\t\t (lhs_expr, pState) = wantPattern pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| token == LeftArrowToken\n\t\t\t= want_generators IsListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState\n\t\t| token == LeftArrowColonToken\n\t\t\t= want_generators IsArrayGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState\n\t\t| token == LeftArrowWithBarToken\n\t\t\t= want_generators IsOverloadedListGenerator (toLineAndColumn qual_position) qual_filename lhs_expr pState\n\t\t\t= ({qual_generators = [], qual_let_defs=LocalParsedDefs [], qual_filter = No, qual_position = {lc_line = 0, lc_column = 0}, qual_filename = \"\" },\n\t\t\t\t\tparseError \"comprehension: qualifier\" (Yes token) \"qualifier(s)\" pState)\n\n\twant_generators :: !GeneratorKind !LineAndColumn !FileName !ParsedExpr !ParseState -> (!Qualifier, !ParseState)\n\twant_generators gen_kind qual_position qual_filename pattern_exp pState\n\t\t# (gen_position, pState)\t\t\t= getPosition pState\n\t\t# (gen_expr, pState) = wantExpression pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t generator = { gen_kind = gen_kind, gen_expr = gen_expr, gen_pattern = pattern_exp,\n\t\t\t\t\t\tgen_position = toLineAndColumn gen_position }\n\t\t| token == AndToken\n\t\t\t# (qualifier, pState) = want_qualifier pState\n\t\t\t= ({qualifier & qual_generators = [ generator : qualifier.qual_generators] }, pState)\n\t\t\t# (let_defs,filter,pState)= parse_optional_lets_and_filter token pState\n\t\t\t= ( {qual_generators = [generator], qual_let_defs=let_defs, qual_filter = filter, qual_position = qual_position, qual_filename = qual_filename}\n\t\t\t ,\tpState )\n\n\tparse_optional_lets_and_filter :: !Token !ParseState -> (!LocalDefs,!Optional ParsedExpr,!ParseState)\n\tparse_optional_lets_and_filter BarToken pState\n\t\t# (filter_expr, pState) = wantExpression pState\n\t\t= (LocalParsedDefs [], Yes filter_expr,pState)\n\tparse_optional_lets_and_filter CommaToken pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token<>LetToken False\n\t\t\t= (LocalParsedDefs [],No,tokenBack (tokenBack pState))\n\t\t# (locals,pState) = wantLocals pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t# (filter,pState) = parse_optional_filter token pState\n\t\t= (locals,filter,pState);\n\tparse_optional_lets_and_filter token pState\n\t\t= (LocalParsedDefs [], No,tokenBack pState)\n\n\tparse_optional_filter :: !Token !ParseState -> (!Optional ParsedExpr,!ParseState)\n\tparse_optional_filter BarToken pState\n\t\t# (filter_expr, pState) = wantExpression pState\n\t\t= (Yes filter_expr,pState)\n\tparse_optional_filter token pState\n\t\t= (No,tokenBack pState)\n\n\/**\n\tCase Expressions\n**\/\n\nwantCaseExp :: !ParseState -> (ParsedExpr, !ParseState)\nwantCaseExp pState\n\t# (case_ident, pState) = internalIdent \"_c\" pState\n\t (case_exp, pState)\t= wantExpression pState\n\t pState\t\t\t\t= wantToken FunctionContext \"case expression\" OfToken pState\n\t pState\t\t\t\t= wantBeginGroup \"case\" pState\n\t (case_alts, (definingSymbol,pState))\n\t \t\t\t\t\t\t= parseList tryCaseAlt (RhsDefiningSymbolCase, pState)\n\t (found, alt, pState)\t= tryLastCaseAlt definingSymbol pState\n\t| found\n\t\t= (PE_Case case_ident case_exp (case_alts++[alt]), wantEndCase pState)\n\t\t= (PE_Case case_ident case_exp case_alts, wantEndCase pState)\nwhere\n\ttryCaseAlt :: (!RhsDefiningSymbol, !ParseState) -> (!Bool, CaseAlt, (!RhsDefiningSymbol, !ParseState))\n\ttryCaseAlt (definingSymbol, pState)\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t# (fname,linenr,pState) = getFileAndLineNr pState\n\t\t# (succ, pattern, pState) = try_pattern token pState\n\t\t| succ\n\t\t\t# (rhs, definingSymbol, pState) = wantRhs True definingSymbol pState\n\t\t\t= (True, { calt_pattern = pattern, calt_rhs = rhs, calt_position=LinePos fname linenr }, (definingSymbol, pState))\n\t\t\/\/ otherwise \/\/ ~ succ\n\t\t\t= (False, abort \"no case alt\", (definingSymbol, pState))\n\t\n\ttryLastCaseAlt :: !RhsDefiningSymbol !ParseState -> (!Bool, CaseAlt, !ParseState)\n\ttryLastCaseAlt definingSymbol pState\n\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t| isDefiningSymbol definingSymbol token\n\t\t\t# (fname,linenr,pState) = getFileAndLineNr pState\n\t\t\t pState\t\t\t= tokenBack pState\n\t\t\t (rhs, _, pState) = wantRhs True definingSymbol pState\n\t\t\t= (True, { calt_pattern = PE_WildCard, calt_rhs = rhs, calt_position=LinePos fname linenr }, pState)\n\t\t| token == OtherwiseToken\n\t\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t\t (fname,linenr,pState) = getFileAndLineNr pState\n\t\t\t pState\t\t\t= tokenBack pState\n\t\t\t| isDefiningSymbol definingSymbol token\n\t\t\t\t# (rhs, _, pState) = wantRhs True definingSymbol pState\n\t\t\t\t= (True, { calt_pattern = PE_WildCard, calt_rhs = rhs, calt_position=LinePos fname linenr }, pState)\n\t\t\t\t= (False, abort \"no case alt\", pState)\n\t\t\t= (False, abort \"no case alt\", tokenBack pState)\n\n\/\/\tcaseSeperator t = t == EqualToken || t == ArrowToken \/\/ to enable Clean 1.3.x case expressions\n\n\t\/\/ FIXME: it would be better if this would use (tryExpression cIsNotPattern)\n\t\/\/ but there's no function tryExpression available yet\n\ttry_pattern :: !Token !ParseState -> (!Bool, ParsedExpr, !ParseState)\n\ttry_pattern token pState\n\t\t# (succ, expr, pState) = trySimplePatternT token pState\n\t\t| succ\n\t\t\t# (succ, expr2, pState) = trySimplePattern pState\n\t\t\t| succ\n\t\t\t\t# (exprs, pState) = parseList trySimplePattern pState\n\t\t\t\t# list = PE_List [expr,expr2 : exprs]\n\t\t\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t\t\t| token == DoubleColonToken\n\t\t\t\t\t# (dyn_type, pState) = wantDynamicTypeInPattern pState\n\t\t\t\t\t= (True, PE_DynamicPattern list dyn_type, pState)\n\t\t\t\t\t= (True, list, tokenBack pState)\n\t\t\t\t= (True, expr, pState)\n\t\t\t= (False, abort \"no expression\", pState)\n\n:: NestedUpdate =\n\t{\tnu_selectors :: ![ParsedSelection]\n\t,\tnu_update_expr :: !ParsedExpr\n\t}\n\nerrorIdent :: Ident\nerrorIdent\n\t=\t{id_name = \"<>\", id_info = nilPtr}\n\nbuildNodeDef :: ParsedExpr ParsedExpr -> ParsedDefinition\nbuildNodeDef lhsExpr rhsExpr\n\t=\tPD_NodeDef NoPos lhsExpr rhs\n\twhere\n\t\trhs\t=\n\t\t\t{ rhs_alts\n\t\t\t\t= UnGuardedExpr\n\t\t\t\t\t{ ewl_nodes\t\t= []\n\t\t\t\t\t, ewl_locals\t= LocalParsedDefs []\n\t\t\t\t\t, ewl_expr\t\t= rhsExpr\n\t\t\t\t\t, ewl_position\t= NoPos\n\t\t\t\t\t}\n\t\t\t, rhs_locals\n\t\t\t\t= LocalParsedDefs []\n\t\t\t}\n\n\/**\n\tRecord expressions\n**\/\n\nwantRecordOrArrayExp :: !Bool !ParseState -> (ParsedExpr, !ParseState)\nwantRecordOrArrayExp is_pattern pState\n\t| is_pattern\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == SquareOpenToken\n\t\t\t# (elems, pState) = want_array_assignments pState\n\t\t\t= (PE_ArrayPattern elems, wantToken FunctionContext \"array selections in pattern\" CurlyCloseToken pState)\n\t\t| token == CurlyCloseToken\n\t\t\t= (PE_Empty, parseError \"record or array pattern\" No \"Array denotation not\" pState)\n\t\t\/\/ otherwise \/\/ is_pattern && token <> SquareOpenToken\n\t\t\t= want_record_pattern token pState\n\t\/\/ otherwise \/\/ ~ is_pattern\n\t# pState=appScanState setNoNewOffsideForSeqLetBit pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t# pState=appScanState clearNoNewOffsideForSeqLetBit pState\n\t= case token of\n\t\tExclamationToken\n\t\t\t-> want_array_elems StrictArray pState\n\t\tSeqLetToken False\n\t\t\t-> want_array_elems UnboxedArray pState\n\t\tCurlyCloseToken\n\t\t\t-> (PE_ArrayDenot OverloadedArray [], pState)\n\t\t_\n\t\t\t# (opt_type, pState) = try_type_specification token pState\n\t\t\t-> case opt_type of\n\t\t\t\tNoRecordName\n\t\t\t\t\t# (succ, field, pState) = try_field_assignment token pState\n\t\t\t\t\t| succ\n\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t| token == CommaToken\n\t\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t (fields, pState) = want_field_assignments cIsNotAPattern token pState\n\t\t\t\t\t\t\t-> (PE_Record PE_Empty NoRecordName [ field : fields ], wantToken FunctionContext \"record or array\" CurlyCloseToken pState)\n\t\t\t\t\t\t| token == CurlyCloseToken\n\t\t\t\t\t\t\t-> (PE_Record PE_Empty NoRecordName [ field ], pState)\n\t\t\t\t\t\t\t-> (PE_Record PE_Empty NoRecordName [ field ], parseError \"record or array\" (Yes token) \"}\" pState)\n\t\t\t\t\t# (expr, pState) = wantExpressionT token pState\n\t\t\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t| token == AndToken\n\t\t\t\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t-> want_record_or_array_update token expr pState\n\t\t\t\t\t| token == DoubleBackSlashToken\n\t\t\t\t\t\t-> wantArrayComprehension OverloadedArray expr pState\n\t\t\t\t\t# (elems, pState) = want_more_array_elems token pState\n\t\t\t\t\t-> (PE_ArrayDenot OverloadedArray [expr : elems], pState)\n\t\t\t\topt_type\n\t\t\t\t\t-> want_record opt_type pState\nwhere\n\twant_array_elems array_kind pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == CurlyCloseToken\n\t\t\t= (PE_ArrayDenot array_kind [], pState)\n\t\t\t# (expr, pState) = wantExpressionT token pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == DoubleBackSlashToken\n\t\t\t\t= wantArrayComprehension array_kind expr pState\n\t\t\t\t# (elems, pState) = want_more_array_elems token pState\n\t\t\t\t= (PE_ArrayDenot array_kind [expr:elems], pState)\n\n\twant_more_array_elems CurlyCloseToken pState\n\t\t= ([], pState)\n\twant_more_array_elems CommaToken pState\n\t\t# (elem, pState) = wantExpression pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t (elems, pState) = want_more_array_elems token pState\n\t\t= ([elem : elems], pState)\n\twant_more_array_elems token pState\n\t\t= ([], parseError \"array elements\" (Yes token) \"\" pState)\n\t\n\twant_record_pattern (IdentToken name) pState\n\t\t| isUpperCaseName name\n\t\t\t# pState = wantToken FunctionContext \"record pattern\" BarToken pState\n\t\t\t (type_id, pState) = stringToIdent name IC_Type pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (fields, pState) = want_field_assignments cIsAPattern token pState\n\t\t\t= (PE_Record PE_Empty (RecordNameIdent type_id) fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState)\n\twant_record_pattern (QualifiedIdentToken module_name record_name) pState\n\t\t| isUpperCaseName record_name\n\t\t\t# pState = wantToken FunctionContext \"record pattern\" BarToken pState\n\t\t\t (module_id, pState) = stringToQualifiedModuleIdent module_name record_name IC_Type pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (fields, pState) = want_field_assignments cIsAPattern token pState\n\t\t\t= (PE_Record PE_Empty (RecordNameQualifiedIdent module_id record_name) fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState) \n\twant_record_pattern token pState\n\t\t# (fields, pState) = want_field_assignments cIsAPattern token pState\n\t\t= (PE_Record PE_Empty NoRecordName fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState) \n\n\ttry_type_specification (IdentToken type_name) pState\n\t\t| isUpperCaseName type_name || isFunnyIdName type_name\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == BarToken\n\t\t\t\t# (type_id, pState) = stringToIdent type_name IC_Type pState\n\t\t\t\t= (RecordNameIdent type_id, pState)\n\t\t\t\t= (NoRecordName, tokenBack pState)\n\t\t\t= (NoRecordName, pState)\n\ttry_type_specification (QualifiedIdentToken module_name record_name) pState\n\t\t| isUpperCaseName record_name || isFunnyIdName record_name\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == BarToken\n\t\t\t\t# (module_ident, pState) = stringToQualifiedModuleIdent module_name record_name IC_Type pState\n\t\t\t\t= (RecordNameQualifiedIdent module_ident record_name, pState)\n\t\t\t\t= (NoRecordName, tokenBack pState)\n\t\t\t= (NoRecordName, pState)\n\ttry_type_specification _ pState\n\t\t= (NoRecordName, pState)\n\nwant_updates :: !OptionalRecordName Token ParseState -> ([NestedUpdate], ParseState)\nwant_updates type token pState\n\t# (updates, pState)\n\t\t= parse_updates token pState\n\/\/ RWS FIXME error message if updates == []\n\t= (updates, pState)\nwhere\n\tparse_updates :: Token ParseState -> ([NestedUpdate], ParseState)\n\tparse_updates token pState\n\t\t# (update, pState) = want_update token pState\n\t\t (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t (updates, pState) = parse_updates token pState \n\t\t\t= ([update : updates], pState)\n\t\t\/\/ otherwise\n\t\t\t= ([update], tokenBack pState)\n\n\twant_update :: Token ParseState -> (NestedUpdate, ParseState)\n\twant_update token pState\n\t\t# (selectors, token, pState) = wantSelectors token pState\n\t\t| token == EqualToken\n\t\t\t# (expr, pState) = wantExpression pState\n\t\t\t= ({nu_selectors = selectors, nu_update_expr = expr}, pState)\n\t\t\t= ({nu_selectors = selectors, nu_update_expr = PE_Empty}, parseError \"field assignment\" (Yes token) \"=\" pState)\n\ntransform_record_or_array_update :: !OptionalRecordName ParsedExpr [NestedUpdate] !Int ParseState -> (ParsedExpr, ParseState)\ntransform_record_or_array_update type expr updates level pState\n\t| is_record_update sortedUpdates\n\t\t=\ttransform_record_update type expr groupedUpdates level pState\n\t\/\/ otherwise\n\t\t=\ttransform_array_update expr updates level pState\n\twhere\n\t\tsortedUpdates\n\t\t\t\/\/ sort updates by first field name, array updates last\n\t\t\t=\tsortBy smaller_update updates\n\t\t\twhere\n\t\t\t\tsmaller_update :: NestedUpdate NestedUpdate -> Bool\n\t\t\t\tsmaller_update a b\n\t\t\t \t\t=\tsmaller_selector (hd a.nu_selectors) (hd b.nu_selectors)\n\t\t \t\t\twhere\n\t\t\t\t\t\tsmaller_selector :: ParsedSelection ParsedSelection -> Bool\n\t\t\t\t\t\tsmaller_selector (PS_Record ident1 _) (PS_Record ident2 _)\n\t\t\t\t\t\t\t=\tident1.id_name < ident2.id_name\n\t\t\t\t\t\tsmaller_selector (PS_Record ident1 _) (PS_QualifiedRecord _ field_name2 _)\n\t\t\t\t\t\t\t=\tident1.id_name < field_name2\n\t\t\t\t\t\tsmaller_selector (PS_Record _ _) _\n\t\t\t\t\t\t\t=\tTrue\n\t\t\t\t\t\tsmaller_selector (PS_QualifiedRecord _ field_name1 _) (PS_QualifiedRecord _ field_name2 _)\n\t\t\t\t\t\t\t=\tfield_name1 < field_name2\n\t\t\t\t\t\tsmaller_selector (PS_QualifiedRecord _ field_name1 _) (PS_Record ident2 _)\n\t\t\t\t\t\t\t=\tfield_name1 < ident2.id_name\n\t\t\t\t\t\tsmaller_selector (PS_QualifiedRecord _ _ _) _\n\t\t\t\t\t\t\t=\tTrue\n\t\t\t\t\t\tsmaller_selector _ _\n\t\t\t\t\t\t\t=\tFalse\n\n\t\tgroupedUpdates\n\t\t\t\/\/ group nested updates by first field name\n\t\t\t=\tgroupBy equal_update sortedUpdates\n\t\t\twhere\n\t\t\t\tequal_update :: NestedUpdate NestedUpdate -> Bool\n\t\t\t\tequal_update a b\n\t\t\t\t\t=\tequal_selectors a.nu_selectors b.nu_selectors\n\t\t \t\t\twhere\n\t\t\t\t\t\tequal_selectors :: [ParsedSelection] [ParsedSelection] -> Bool\n\t\t\t\t\t\tequal_selectors [PS_Record ident1 _ ,_ : _] [PS_Record ident2 _ ,_: _]\n\t\t\t\t\t\t\t=\tident1.id_name == ident2.id_name\n\t\t\t\t\t\tequal_selectors [PS_QualifiedRecord _ field_name1 _ ,_ : _] [PS_QualifiedRecord _ field_name2 _ ,_: _]\n\t\t\t\t\t\t\t=\tfield_name1 == field_name2\n\t\t\t\t\t\tequal_selectors _ _\n\t\t\t\t\t\t\t=\tFalse\n\n\t\tgroupBy :: (a a -> Bool) [a] -> [[a]]\n\t\tgroupBy eq []\n\t\t = []\n\t\tgroupBy eq [h : t]\n\t\t = [[h : this] : groupBy eq other]\n\t\t where\n\t\t (this, other) = span (eq h) t\n\n\t\tis_record_update [{nu_selectors=[select : _]} : _]\n\t\t\t=\tis_record_select select\n\t\tis_record_update updates\n\t\t\t=\tFalse\n\n\t\tis_record_select (PS_Record _ _)\n\t\t\t=\tTrue\n\t\tis_record_select (PS_QualifiedRecord _ _ _)\n\t\t\t=\tTrue\n\t\tis_record_select _\n\t\t\t=\tFalse\n\n\t\ttransform_record_update :: OptionalRecordName ParsedExpr ![[NestedUpdate]] !Int ParseState -> (ParsedExpr, ParseState)\n\t\ttransform_record_update record_type expr groupedUpdates level pState\n\t\t\t=\t(updateExpr, pState2)\n\t\t\twhere\n\t\t\t\t\/* final_record_type on a cycle *\/\n\t\t\t\t(assignments, (optionalIdent, final_record_type,pState2))\n\t\t\t\t\t= mapSt (transform_update level) groupedUpdates (No, record_type,pState)\n\t\t\t\tupdateExpr\n\t\t\t\t\t= build_update final_record_type optionalIdent expr assignments\n\t\t\t\t\/\/ transform one group of nested updates with the same first field\n\t\t\t\t\/\/ for example: f.g1 = e1, f.g2 = e2 -> f = {id.f & g1 = e1, g2 = e2},\n\t\t\t\t\/\/ (id is ident to shared expression that's being updated)\n\n\t\t\t\ttransform_update :: !Int [NestedUpdate] (Optional Ident,OptionalRecordName,ParseState) -> (FieldAssignment, !(!Optional Ident,OptionalRecordName,ParseState))\n\t\t\t\ttransform_update _ [{nu_selectors=[PS_Record fieldIdent field_record_type], nu_update_expr}] (shareIdent,record_type,pState)\n\t\t\t\t\t# (record_type,pState) = check_field_and_record_types field_record_type record_type pState;\n\t\t\t\t\t= ({bind_dst = FieldName fieldIdent, bind_src = nu_update_expr},(shareIdent,record_type,pState))\n\t\t\t\ttransform_update _ [{nu_selectors=[PS_QualifiedRecord module_id field_name field_record_type], nu_update_expr}] (shareIdent,record_type,pState)\n\t\t\t\t\t# (record_type,pState) = check_field_and_record_types field_record_type record_type pState;\n\t\t\t\t\t= ({bind_dst = QualifiedFieldName module_id field_name, bind_src = nu_update_expr},(shareIdent,record_type,pState))\n\t\t\t\ttransform_update level updates=:[{nu_selectors=[PS_Record fieldIdent field_record_type : _]} : _] (optionalIdent,record_type,pState)\n\t\t\t\t\t# (record_type,pState) = check_field_and_record_types field_record_type record_type pState;\n\t\t\t\t\t (shareIdent, pState) = make_ident optionalIdent level pState\n\t\t\t\t\t select = PE_Selection ParsedNormalSelector (PE_Ident shareIdent) [PS_Record fieldIdent final_record_type]\n\t\t\t\t\t (update_expr, pState)\n\t\t\t\t\t \t=\ttransform_record_or_array_update NoRecordName select (map sub_update updates) (level+1) pState\n\t\t\t\t\t= ({bind_dst = FieldName fieldIdent, bind_src = update_expr}, (Yes shareIdent,record_type,pState))\n\t\t\t\ttransform_update level updates=:[{nu_selectors=[PS_QualifiedRecord module_id field_name field_record_type : _]} : _] (optionalIdent,record_type,pState)\n\t\t\t\t\t# (record_type,pState) = check_field_and_record_types field_record_type record_type pState;\n\t\t\t\t\t (shareIdent, pState) = make_ident optionalIdent level pState\n\t\t\t\t\t select = PE_Selection ParsedNormalSelector (PE_Ident shareIdent) [PS_QualifiedRecord module_id field_name final_record_type]\n\t\t\t\t\t (update_expr, pState)\n\t\t\t\t\t \t=\ttransform_record_or_array_update NoRecordName select (map sub_update updates) (level+1) pState\n\t\t\t\t\t= ({bind_dst = QualifiedFieldName module_id field_name, bind_src = update_expr}, (Yes shareIdent,record_type,pState))\n\t\t\t\ttransform_update _ _ (_, record_type,pState)\n\t\t\t\t\t# pState = parseError \"record or array\" No \"field assignments mixed with array assignments not\" pState\n\t\t\t\t\t=\t({bind_dst = FieldName errorIdent, bind_src = PE_Empty}, (No,record_type,pState))\n\n\t\t\t\tmake_ident :: (Optional Ident) !Int ParseState -> (Ident, ParseState)\n\t\t\t\tmake_ident (Yes ident) _ pState\n\t\t\t\t\t=\t(ident, pState)\n\t\t\t\tmake_ident No level pState\n\t\t\t\t\t=\tinternalIdent (\"s\" +++ toString level +++ \";\") pState\n\n\t\t\t\tsub_update :: NestedUpdate -> NestedUpdate\n\t\t\t\tsub_update update=:{nu_selectors}\n\t\t\t\t\t=\t{update & nu_selectors = tl nu_selectors}\n\n\t\t\t\tbuild_update :: !OptionalRecordName !(Optional Ident) !ParsedExpr ![FieldAssignment] -> ParsedExpr\n\t\t\t\tbuild_update record_type No expr assignments\n\t\t\t\t\t=\tPE_Record expr record_type assignments\n\t\t\t\tbuild_update record_type (Yes ident) expr assignments\n\t\t\t\t\t=\tPE_Let (LocalParsedDefs [buildNodeDef (PE_Ident ident) expr])\n\t\t\t\t\t\t\t\t(PE_Record (PE_Ident ident) record_type assignments)\n\t\t\t\t\n\t\t\t\tcheck_field_and_record_types :: OptionalRecordName OptionalRecordName ParseState -> (!OptionalRecordName,!ParseState);\n\t\t\t\tcheck_field_and_record_types NoRecordName record_type pState\n\t\t\t\t\t= (record_type,pState);\n\t\t\t\tcheck_field_and_record_types field_record_type=:(RecordNameIdent _) NoRecordName pState\n\t\t\t\t\t= (field_record_type,pState);\n\t\t\t\tcheck_field_and_record_types (RecordNameIdent field_record_type_name) record_type=:(RecordNameIdent record_type_name) pState\n\t\t\t\t\t| field_record_type_name==record_type_name\n\t\t\t\t\t\t= (record_type,pState);\n\t\t\t\t\t\t# error_message = \"record type in update: \"+++field_record_type_name.id_name+++\" where \"+++record_type_name.id_name+++\" was\"\n\t\t\t\t\t\t= (record_type,parseError \"record or array\" No error_message pState);\n\n\t\ttransform_array_update :: ParsedExpr [NestedUpdate] !Int ParseState -> (ParsedExpr, ParseState)\n\t\ttransform_array_update expr updates level pState\n\t\t\t\/\/ transform { & [i].<...> = e1, ... } to {{ & [i1].<...> = e1} & ...}\n\t\t\t=\tfoldSt (transform_update level) updates (expr, pState)\n\t\t\twhere\n\t\t\t\ttransform_update :: !Int NestedUpdate (ParsedExpr, ParseState) -> (ParsedExpr, ParseState)\n\t\t\t\ttransform_update level {nu_selectors, nu_update_expr} (expr1, pState)\n\t\t\t\t\t=\tbuild_update expr1 (split_selectors nu_selectors) nu_update_expr level pState\n\t\t\t\t\twhere\n\t\t\t\t\t\t\/\/ split selectors into final record selectors and initial selectors\n\t\t\t\t\t\t\/\/ (resulting selectors are reversed)\n\t\t\t\t\t\t\/\/\t\tfor example: [i1].[i2].f.[i3].g.h -> (h.g, [i3].f.[i2].[i1])\n\t\t\t\t\t\tsplit_selectors selectors\n\t\t\t\t\t\t\t=\tspan is_record_select (reverse selectors)\n\n\t\t\t\t\t\tbuild_update :: ParsedExpr ([ParsedSelection], [ParsedSelection]) ParsedExpr !Int ParseState -> (ParsedExpr, ParseState)\n\t\t\t\t\t\tbuild_update expr ([], initial_selectors) update_expr _ pState\n\t\t\t\t\t\t\t=\t(PE_Update expr (reverse initial_selectors) update_expr, pState)\n\t\t\t\t\t\t\/\/ transform { & <...>.[i].f.g. = e1} to\n\t\t\t\t\t\t\/\/ let\n\t\t\t\t\t\t\/\/\t\tindex_id = i\n\t\t\t\t\t\t\/\/\t\t(element_id, array_id) = !<...>.[index_id]\n\t\t\t\t\t\t\/\/\t in {array_id & [index_id] = {element_id & f.g = e1}}\n\t\t\t\t\t\tbuild_update expr (record_selectors, [PS_Array index : initial_selectors]) update_expr level pState\n\t\t\t\t\t\t\t# (index_id, pState)\n\t\t\t\t\t\t\t\t=\tinternalIdent (\"i\" +++ toString level +++ \";\") pState\n\t\t\t\t\t\t\t# (element_id, pState)\n\t\t\t\t\t\t\t\t=\tinternalIdent (\"e\" +++ toString level +++ \";\") pState\n\t\t\t\t\t\t\t# (array_id, pState)\n\t\t\t\t\t\t\t\t=\tinternalIdent (\"a\" +++ toString level +++ \";\") pState\n\t\t\t\t\t\t\t index_def\n\t\t\t\t\t\t\t \t=\tbuildNodeDef (PE_Ident index_id) index\n\t\t\t\t\t\t\t select_def\n\t\t\t\t\t\t\t \t=\tbuildNodeDef\n\t\t\t\t\t\t\t \t\t\t(PE_Tuple [PE_Ident element_id, PE_Ident array_id])\n\t\t\t\t\t\t\t \t\t\t(PE_Selection (ParsedUniqueSelector True) expr (reverse [PS_Array (PE_Ident index_id) : initial_selectors]))\n\t\t\t\t\t\t\t (updated_element, pState)\n\t\t\t\t\t\t\t\t= transform_record_update NoRecordName\n\t\t\t\t\t\t\t\t\t(PE_Ident element_id)\n\t\t\t\t\t\t\t\t\t[[{nu_selectors=(reverse record_selectors), nu_update_expr=update_expr}]] (level+1) pState\n\t\t\t\t\t\t\t=\t(PE_Let\n\t\t\t\t\t\t\t\t\t(LocalParsedDefs [index_def, select_def])\n\t\t\t\t\t\t\t\t\t(PE_Update (PE_Ident array_id) (reverse [PS_Array (PE_Ident index_id) : initial_selectors]) updated_element), pState)\n\nwant_field_assignments is_pattern token=:(IdentToken field_name) pState\n\t| isLowerCaseName field_name\n\t\t# (field_id, pState) = stringToIdent field_name IC_Selector pState\n\t\t= want_more_field_assignments (FieldName field_id) is_pattern pState\nwant_field_assignments is_pattern token=:(QualifiedIdentToken module_name field_name) pState\n\t| isLowerCaseName field_name\n\t\t# (module_id, pState) = stringToIdent module_name (IC_Module NoQualifiedIdents) pState\n\t\t= want_more_field_assignments (QualifiedFieldName module_id field_name) is_pattern pState\nwant_field_assignments is_pattern token pState\n\t= ([], parseError \"record or array field assignments\" (Yes token) \"field name\" pState)\n\nwant_more_field_assignments field_name_or_qualified_field_name is_pattern pState\n\t# (field_expr, pState) = want_field_expression is_pattern pState\n\t field = { bind_src = field_expr, bind_dst = field_name_or_qualified_field_name}\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == CommaToken\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t (fields, pState) = want_field_assignments is_pattern token pState \n\t\t= ([ field : fields ], pState)\n\t\t= ([ field ], tokenBack pState)\n\ntry_field_assignment (IdentToken field_name) pState\n\t| isLowerCaseName field_name\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == EqualToken\n\t\t\t# (field_expr, pState) = wantExpression pState\n\t\t\t (field_id, pState) = stringToIdent field_name IC_Selector pState\n\t\t\t= (True, { bind_src = field_expr, bind_dst = FieldName field_id}, pState) \n\t\t\t= (False, abort \"no field\", tokenBack pState)\n\t\t= (False, abort \"no field\", pState)\ntry_field_assignment (QualifiedIdentToken module_name field_name) pState\n\t| isLowerCaseName field_name\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == EqualToken\n\t\t\t# (field_expr, pState) = wantExpression pState\n\t\t\t (module_id, pState) = stringToIdent module_name (IC_Module NoQualifiedIdents) pState\n\t\t\t= (True, { bind_src = field_expr, bind_dst = QualifiedFieldName module_id field_name}, pState) \n\t\t\t= (False, abort \"no field\", tokenBack pState)\n\t\t= (False, abort \"no field\", pState)\ntry_field_assignment _ pState\n\t= (False, abort \"no field\", pState)\n\nwant_field_expression is_pattern pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == EqualToken\n\t\t= wantExpressionOrPattern is_pattern pState\n\t\t= (PE_Empty, tokenBack pState)\n\nwant_record :: !OptionalRecordName !ParseState -> (!ParsedExpr,!ParseState)\t\t\nwant_record type pState\n\t# (token1, pState) = nextToken FunctionContext pState\n\t (token2, pState) = nextToken FunctionContext pState\n\t| isDefinesFieldToken token2\n\t\t# (fields, pState) = want_field_assignments cIsNotAPattern token1 (tokenBack pState)\n\t\t= (PE_Record PE_Empty type fields, wantToken FunctionContext \"record\" CurlyCloseToken pState)\n\t\t= want_record_update type token1 (tokenBack pState)\nwhere\n\twant_record_update :: !OptionalRecordName !Token !ParseState -> (!ParsedExpr, !ParseState)\n\twant_record_update type token pState\n\t\t# (expr, pState)\t= wantExpressionT token pState\n\t\t pState\t\t\t= wantToken FunctionContext \"record update\" AndToken pState\n\t\t (token, pState)\t= nextToken FunctionContext pState\n\t\t= want_update type expr token pState\n\nwantRecordPatternWithoutDefinitions :: !ParseState -> (ParsedExpr, !ParseState)\nwantRecordPatternWithoutDefinitions pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == CurlyCloseToken\n\t\t= (PE_Empty, parseError \"record pattern\" No \"Array denotation not\" pState)\n\t\t= want_record_pattern_without_definitions token pState\nwhere\n\twant_record_pattern_without_definitions (IdentToken name) pState\n\t\t| isUpperCaseName name\n\t\t\t# pState = wantToken FunctionContext \"record pattern\" BarToken pState\n\t\t\t (type_id, pState) = stringToIdent name IC_Type pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (fields, pState) = want_field_assignments_without_definitions token pState\n\t\t\t= (PE_Record PE_Empty (RecordNameIdent type_id) fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState)\n\twant_record_pattern_without_definitions (QualifiedIdentToken module_name record_name) pState\n\t\t| isUpperCaseName record_name\n\t\t\t# pState = wantToken FunctionContext \"record pattern\" BarToken pState\n\t\t\t (module_id, pState) = stringToQualifiedModuleIdent module_name record_name IC_Type pState\n\t\t\t (token, pState) = nextToken FunctionContext pState\n\t\t\t (fields, pState) = want_field_assignments_without_definitions token pState\n\t\t\t= (PE_Record PE_Empty (RecordNameQualifiedIdent module_id record_name) fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState) \n\twant_record_pattern_without_definitions token pState\n\t\t# (fields, pState) = want_field_assignments_without_definitions token pState\n\t\t= (PE_Record PE_Empty NoRecordName fields, wantToken FunctionContext \"record pattern\" CurlyCloseToken pState) \n\n\twant_field_assignments_without_definitions token=:(IdentToken field_name) pState\n\t\t| isLowerCaseName field_name\n\t\t\t# (field_id, pState) = stringToIdent field_name IC_Selector pState\n\t\t\t= want_more_field_assignments_without_definitions (FieldName field_id) pState\n\twant_field_assignments_without_definitions token=:(QualifiedIdentToken module_name field_name) pState\n\t\t| isLowerCaseName field_name\n\t\t\t# (module_id, pState) = stringToIdent module_name (IC_Module NoQualifiedIdents) pState\n\t\t\t= want_more_field_assignments_without_definitions (QualifiedFieldName module_id field_name) pState\n\twant_field_assignments_without_definitions token pState\n\t\t= ([], parseError \"record field assignments\" (Yes token) \"field name\" pState)\n\n\twant_more_field_assignments_without_definitions field_name_or_qualified_field_name pState\n\t\t# pState = wantToken FunctionContext \"record pattern\" EqualToken pState\n\t\t# (field_expr, pState) = wantPattern pState\n\t\t field = {bind_src = field_expr, bind_dst = field_name_or_qualified_field_name}\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == CommaToken\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t (fields, pState) = want_field_assignments_without_definitions token pState \n\t\t\t= ([field : fields], pState)\n\t\t\t= ([field ], tokenBack pState)\n\nwant_update :: !OptionalRecordName !ParsedExpr !Token !ParseState -> (!ParsedExpr, !ParseState)\nwant_update type expr token pState\n\t# (expr, pState) = want_update_without_curly_close type expr token pState\n\t pState = wantToken FunctionContext \"update\" CurlyCloseToken pState\n\t= (expr, pState)\n\nwant_update_without_curly_close :: !OptionalRecordName !ParsedExpr !Token !ParseState -> (!ParsedExpr, !ParseState)\nwant_update_without_curly_close type expr token pState\n\t# (position, pState) = getPosition pState\n\t (updates, pState)\t= want_updates type token pState\n\t (qualifiers, pState) = try_qualifiers pState\n\t (updatable_expr, pState) = test_qualifiers expr (toLineAndColumn position) qualifiers pState\n\t (updated_expr, pState) = transform_record_or_array_update type updatable_expr updates 0 pState\n\t= (add_qualifiers qualifiers expr updated_expr updatable_expr, pState)\n\twhere\n\t\ttry_qualifiers :: !ParseState -> (![Qualifier], !ParseState)\n\t\ttry_qualifiers pState\n\t\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t\t| token == DoubleBackSlashToken\n\t\t\t\t= wantQualifiers pState\n\t\t\t\t= ([], tokenBack pState)\n\n\t\ttest_qualifiers :: !ParsedExpr !LineAndColumn [Qualifier] !ParseState -> (!ParsedExpr, !ParseState)\n\t\ttest_qualifiers updateExpr _ [] pState\n\t\t\t=\t(updateExpr, pState)\n\t\ttest_qualifiers updateExpr {lc_line, lc_column} qualifiers pState\n\t\t\t# (ident, pState)\n\t\t\t\t=\tstringToIdent (\"a;\" +++ toString lc_line +++ \";\" +++ toString lc_column) IC_Expression pState\n\t\t\t=\t(PE_Ident ident, pState)\n\n\t\tadd_qualifiers :: ![Qualifier] !ParsedExpr !ParsedExpr !ParsedExpr -> ParsedExpr\n\t\tadd_qualifiers [] _ update_expr _\n\t\t\t=\tupdate_expr\n\t\tadd_qualifiers qualifiers expr update_expr ident_expr\n\t\t\t=\tPE_UpdateComprehension expr update_expr ident_expr qualifiers\n\nwant_record_or_array_update token expr pState\n\t= want_update NoRecordName expr token pState\n\nwant_array_assignments pState\n\t# (assign, pState) = want_array_assignment pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == CommaToken\n\t\t# pState = wantToken FunctionContext \"array assignments\" SquareOpenToken pState\n\t\t (assigns, pState) = want_array_assignments pState \n\t\t= ([ assign : assigns ], pState)\n\t\t= ([ assign ], tokenBack pState)\nwhere\n\twant_array_assignment pState\n\t\t# (index_exprs, pState) = want_index_exprs pState\n\t\t pState = wantToken FunctionContext \"array assignment\" EqualToken pState\n\t\t (pattern_exp, pState) = wantPattern pState\n\t\t= ({bind_dst = index_exprs, bind_src = pattern_exp}, pState)\n\n\twant_index_exprs pState\n\t\t# (index_expr, pState) = wantExpression pState\n\t\t (token, pState) = nextToken GeneralContext pState\n\t\t| token==CommaToken\n\t\t\t# (index_exprs, pState) = want_index_exprs pState\n\t\t\t= ([index_expr:index_exprs], pState)\n\t\t| token==SquareCloseToken\n\t\t\t= ([index_expr], pState)\n\t\t= ([], parseError \"\" (Yes token) \"] or ,\" pState)\n\/**\n\tEnd of definitions\n**\/\n\nskipToEndOfDefinition :: !ParseState -> (!Token, !ParseState)\nskipToEndOfDefinition pState\n\t# (token, pState)\t\t= nextToken FunctionContext pState\n\t= case token of\n\t\tNewDefinitionToken\t-> (token, pState)\n\t\tEndGroupToken\t\t-> (token, pState)\n\t\tEndOfFileToken\t\t-> (token, pState)\n\/\/\t\tSemicolonToken\t\t-> (token, pState) \/\/ might be useful in non layout mode.\n\t\t_\t\t\t\t\t-> skipToEndOfDefinition pState \/\/ -->> (token,\"skipped\")\n\nwantEndCodeRhs :: !ParseState -> ParseState\nwantEndCodeRhs pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t| ss_useLayout\n\t\t= wantEndOfDefinition \"code rhs\" pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == SemicolonToken\n\t\t= pState\n\t\t= tokenBack pState\n\nwantEndOfDefinition :: String !ParseState -> ParseState\nwantEndOfDefinition msg pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t#\t(token, pState) = skipToEndOfDefinition {pState & ps_flags = pState.ps_flags bitand (bitnot PS_SkippingMask)}\n\t\t= want_end_of_definition token msg pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t= want_end_of_definition token msg pState\nwhere\n\twant_end_of_definition :: !Token String !ParseState -> ParseState\n\twant_end_of_definition token msg pState\n\t\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t\t| ss_useLayout\n\t\t\t= case token of\n\t\t\t\tNewDefinitionToken\t->\tpState \n\t\t\t\tEndOfFileToken\t\t->\ttokenBack pState\n\t\t\t\tEndGroupToken \t\t->\ttokenBack pState\n\t\t\t\tInToken\t\t \t\t->\ttokenBack pState\n\t\t\t\tWhereToken\t\t\t->\ttokenBack pState\n\t\t\t\tBarToken\t\t\t->\ttokenBack pState\n\t\t\t\tEqualToken\t\t\t->\ttokenBack pState\n\t\t\t\tArrowToken\t\t\t->\ttokenBack pState\n\t\t\t\tSeqLetToken _\t\t->\ttokenBack pState\n\t\t\t\tSemicolonToken\t\t#\t(token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t\t\t->\tcase token of\n\t\t\t\t\t\t\t\t\t\t\tNewDefinitionToken\t->\tpState\n\t\t\t\t\t\t\t\t\t\t\t_\t\t\t\t\t->\ttokenBack pState\n\t\t\t\ttoken\t\t\t\t->\twantEndOfDefinition \"\" (parseError msg (Yes token) \"end of definition\" pState)\n\t\t\/\/ otherwise \/\/ ~ ss_useLayout\n\t\t\t= case token of\n\t\t\t\tCurlyCloseToken\t\t->\ttokenBack pState\n\t\t\t\tSemicolonToken\t\t->\tpState\n\t \t\t\tEndOfFileToken\t\t->\ttokenBack pState\n\t\t\t\ttoken\t\t\t\t->\twantEndOfDefinition \"\" (parseError msg (Yes token) \"end of definition\" pState)\n\nwantEndRootExpression :: !ParseState -> ParseState\nwantEndRootExpression pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t=\twantEndOfDefinition \"root expression\" pState\n\t\t#\t(token, pState)\t\t\t= nextToken FunctionContext pState\n\t\t\t(ss_useLayout, pState)\t= accScanState UseLayout pState\n\t\t| ss_useLayout\n\t\t\t= case token of\n\t\t\t\tNewDefinitionToken\t->\tpState\n\t\t\t\tEndOfFileToken\t\t->\ttokenBack pState\n\t\t\t\tEndGroupToken \t\t->\ttokenBack pState\n\t\t\t\tEqualToken \t\t\t->\ttokenBack pState\n\t\t\t\tArrowToken \t\t\t->\ttokenBack pState\n\t\t\t\tWhereToken\t\t\t->\ttokenBack pState\n\t\t\t\tWithToken\t\t\t->\ttokenBack pState\n\t\t\t\tBarToken\t\t\t->\ttokenBack pState\n\t\t\t\tInToken\t\t \t\t->\ttokenBack pState\n\t\t\t\tCloseToken\t \t\t->\ttokenBack pState\n\t\t\t\tSquareCloseToken\t->\ttokenBack pState\n\t\t\t\tCommaToken\t \t\t->\ttokenBack pState\n\t\t\t\tColonToken\t \t\t->\ttokenBack pState\n\t\t\t\t(SeqLetToken _)\t\t->\ttokenBack pState\n\t\t\t\tSemicolonToken\t\t#\t(token, pState) = nextToken FunctionContext pState\n\t\t\t\t\t\t\t\t\t->\tcase token of\n\t\t\t\t\t\t\t\t\t\t\tNewDefinitionToken\t->\tpState\n\t\t\t\t\t\t\t\t\t\t\t_\t\t\t\t\t->\ttokenBack pState\n\t\t\t\tCurlyCloseToken\t\t->\ttokenBack pState \n\t\t\t\ttoken\t\t\t\t->\twantEndOfDefinition \"root expression\" (parseError \"root expression\" (Yes token) \"end of root expression\" pState)\n\t\t\/\/ otherwise \/\/ ~ ss_useLayout\n\t\t\t= case token of\n\t\t\t\tSemicolonToken\t\t->\tpState\n\t\t\t\tCurlyCloseToken\t\t->\ttokenBack pState\n\t\t\t\tEqualToken \t\t\t->\ttokenBack pState\n\t\t\t\tArrowToken \t\t\t->\ttokenBack pState\n\t\t\t\t(SeqLetToken _)\t\t->\ttokenBack pState\n\t\t\t\tWhereToken\t\t\t->\ttokenBack pState\n\t\t\t\tWithToken\t\t\t->\ttokenBack pState\n\t\t\t\tBarToken\t\t\t->\ttokenBack pState\n\t \t\t\tEndOfFileToken\t\t->\ttokenBack pState\n\t\t\t\ttoken\t\t\t\t->\twantEndOfDefinition \"root expression\" (parseError \"root expression\" (Yes token) \"end of root expression\" pState)\n\nwantEndGroup :: String !ParseState -> ParseState\nwantEndGroup msg pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == EndOfFileToken\n\t\t= tokenBack pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t| ss_useLayout\n\t\t= case token of\n\t\t\tEndGroupToken\t->\tpState\n\t\t\tInToken\t\t\t->\ttokenBack pState\n\t\t\t_\t\t\t\t->\tparseError msg (Yes token) \"end of group with layout\" pState\n\t\/\/ ~ ss_useLayout\n\t| token == CurlyCloseToken\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == SemicolonToken\n\t\t\t= pState\n\t\t\t= tokenBack pState\n\t\t= parseError msg (Yes token) \"end of group without layout, },\" pState\n\nwantEndModule :: !ParseState -> ParseState\nwantEndModule pState\n\t# (token, pState) = nextToken FunctionContext pState\n\t| token == EndOfFileToken\n\t\t= tokenBack pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t| ss_useLayout && token == EndGroupToken\n\t\t= pState\n\t\t= parseError \"Definition\" (Yes token) \"Unexpected token in input: definition\" pState\n\nwantEndNestedGuard :: !Bool !Int !ParseState -> ParseState\nwantEndNestedGuard defaultFound offside pState\n\t| ~ defaultFound\n\t\t= parseError \"nested guards\" No \"sorry, but for the time being there is a default alternative for nested guards\" pState\n\t# (token, pState)\t\t\t= nextToken FunctionContext pState\n\t| token == EndOfFileToken\n\t\t= tokenBack pState\n\t# (ss_useLayout, pState)\t= accScanState UseLayout pState\n\t| ss_useLayout\n\t\t# ({fp_col}, pState)\t= getPosition pState\n\t\t| fp_col < offside || (end_Nested_Guard token && fp_col == offside)\n\t\t\t= tokenBack pState\n\t\t\/\/ otherwise\n\t\t\t= parseError \"nested guards\" (Yes token) \"=, ->, | or # at offside position, or end of function definition\" pState\n\t\/\/ ~ ss_useLayout\n\t| token == SemicolonToken\n\t\t= pState\n\t| defaultFound\n\t\t= tokenBack pState\n\t\/\/ otherwise\n\t\t= parseError \"nested guards\" (Yes token) \"End of nested guards, ;,\" pState\nwhere\n\tend_Nested_Guard EqualToken\t\t\t= True\n\tend_Nested_Guard BarToken\t\t\t= True\n\tend_Nested_Guard ArrowToken\t\t\t= True\n\tend_Nested_Guard (SeqLetToken _)\t= True\n\tend_Nested_Guard _\t\t\t\t\t= False\n\nwantEndLocals :: !ParseState -> ParseState\nwantEndLocals pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == EndOfFileToken && ss_useLayout\n\t\t= tokenBack pState\n\t| ss_useLayout\n\t\t= case token of\n\t\t\tEndGroupToken\t->\tpState\n\t\t\tInToken\t\t\t->\ttokenBack (appScanState dropOffsidePosition pState) \/\/ PK\n\t\/\/\t\tInToken\t\t\t->\ttokenBack pState\t\/\/ For let expressions with cases\n\t\t\t_\t\t\t\t->\tparseError \"local definitions\" (Yes token) \"end of locals with layout\" pState\n\t\/\/ ~ ss_useLayout\n\t| token == CurlyCloseToken\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t| token == SemicolonToken\n\t\t\t= pState\n\t\t\t= tokenBack pState\n\t\/\/ otherwise \/\/ token <> CurlyCloseToken\n\t\t= parseError \"local definitions\" (Yes token) \"end of locals without layout, },\" pState\n\nwantEndCase :: !ParseState -> ParseState\nwantEndCase pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t (token, pState) = nextToken FunctionContext pState\n\t| token == EndOfFileToken\n\t\t= tokenBack pState\n\t| ss_useLayout\n\t\t= case token of\n\t\t\tEndGroupToken\t\t->\tpState\n\t\t\tCloseToken\t\t\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tSquareCloseToken\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tSemicolonToken\t\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tCommaToken\t\t\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tColonToken\t\t\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tInToken\t\t\t\t->\ttokenBack (appScanState dropOffsidePosition pState)\n\t\t\tCurlyCloseToken\t\t->\ttokenBack (appScanState dropOffsidePosition pState) \/\/ PK\n\t\t\t_\t\t\t\t\t->\tparseError \"case expression\" (Yes token) \"end of case with layout\" pState\n\t\/\/ ~ ss_useLayout\n\t| token == CurlyCloseToken\n\t\t= pState\n\t\/\/ otherwise \/\/ token <> CurlyCloseToken\n\t\t= parseError \"case expression\" (Yes token) \"end of group without layout, },\" pState\n\nwantBeginGroup :: String !ParseState -> ParseState\nwantBeginGroup msg pState\n\t# (ss_useLayout, pState) = accScanState UseLayout pState\n\t| ss_useLayout\n\t\t= pState\n\t\/\/ otherwise \/\/ ~ ss_uselayout\n\t\t# (token, pState)\t= nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tCurlyOpenToken\n\t\t\t\t->\tpState\n\t\t\t_\t->\tparseError msg (Yes token) \"begin group without layout, {,\" pState\n\n\/\/ AA..\nwantKind :: !ParseState -> (!TypeKind, !ParseState)\nwantKind pState\n\t| pState.ps_flags bitand PS_SupportGenericsMask==0\n\t\t= (KindConst, parseErrorSimple \"kind\" \"to enable generics use -generics command line flag\" pState)\n\t# (token, pState) = nextToken TypeContext pState\n\t# (kind, pState) = want_simple_kind token pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= want_kind kind token pState\n\twhere\n\t\twant_simple_kind AsteriskToken pState\t\t= (KindConst, pState)\n\t\twant_simple_kind (IntToken str) pState\n\t\t\t# n = toInt str\n\t\t\t| n == 0\t= (KindConst, pState)\n\t\t\t| n > 0 \t= (KindArrow (repeatn n KindConst), pState)\n\t\t\t| otherwise = (KindConst, parseError \"invalid kind\" No \"positive integer expected\" pState)\n\t\twant_simple_kind OpenToken pState \t\t\t= wantKind pState\n\t\twant_simple_kind GenericOpenToken pState \t= wantKind pState\n\t\twant_simple_kind token pState \n\t\t\t= (KindConst, parseError \"invalid kind\" (Yes token) \"* or (\" pState)\n\n\t\twant_kind kind ArrowToken pState\n\t\t\t# (rhs, pState) = wantKind pState\n\t\t\t= \tcase rhs of\n\t\t\t\t(KindArrow ks) \t-> (KindArrow [kind : ks], pState)\n\t\t\t\tKindConst \t\t-> (KindArrow [kind], pState) \n\t\t\t\t\/\/_\t\t\t\t-> (KindArrow [kind, rhs], pState)\n\t\twant_kind kind CloseToken pState \t\t\t\t= (kind, pState)\n\t\twant_kind kind GenericCloseToken pState \t\t= (kind, pState)\n\t\twant_kind kind token pState\t\n\t\t\t= (kind, parseError \"invalid kind\" (Yes token) \")\" pState)\n\/\/ ..AA \n\n\/*\n\tFunctions on the parse pState\n*\/\n\/*\ninstance insertToken ParseState\nwhere\n\tinsertToken t c pState = appScanState (insertToken t c) pState\n\ninstance currentToken ParseState\nwhere\n\tcurrentToken pState = accScanState currentToken pState\n\t\ninstance replaceToken ParseState\nwhere\n\treplaceToken t pState = appScanState (replaceToken t) pState\n*\/\ninstance tokenBack ParseState\nwhere\n\ttokenBack pState\n\t\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t\t= pState\n\t\t\t= appScanState tokenBack pState\n\ninstance nextToken ParseState\nwhere\n\tnextToken :: !ScanContext !ParseState -> (!Token, !ParseState)\n\tnextToken scanContext pState\n\t\t| pState.ps_flags bitand PS_SkippingMask<>0 \/\/ in error recovery from parse error\n\t\t\t= (ErrorToken \"Skipping\", pState)\n\t\t\t= accScanState (nextToken scanContext) pState\n\ninstance getPosition ParseState\nwhere\n\tgetPosition pState = accScanState getPosition pState\n\nwarnIfStrictAnnot NoAnnot pState = pState\nwarnIfStrictAnnot (StrictAnnotWithPosition position) pState = parseWarningWithPosition \"\" \"! ignored\" position pState\n\nparseWarningWithPosition :: !{# Char} !{# Char} !FilePosition !ParseState -> ParseState\nparseWarningWithPosition act msg position pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t= pState\n\t| otherwise \/\/ not pState.ps_skipping\n\t\t# (filename,pState=:{ps_error={pea_file,pea_ok}})\t= getFilename pState\n\t\t pea_file \t= \tpea_file\n\t\t \t\t\t\t<<< \"Parse warning [\"\n\t\t \t\t\t\t<<< filename <<< \",\"\n\t\t \t\t\t\t<<< position\n\t\t \t\t\t\t<<< (if (size act > 0) (\",\" + act) \"\") <<< \"]: \"\n\t\t \t\t\t\t<<< msg\n\t\t \t\t\t\t<<< \"\\n\"\n\t\t=\t{ pState\n\t\t\t& ps_error\t\t= { pea_file = pea_file, pea_ok = pea_ok }\n\t\t\t}\n\nparseWarning :: !{# Char} !{# Char} !ParseState -> ParseState\nparseWarning act msg pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t= pState\n\t| otherwise \/\/ not pState.ps_skipping\n\t\t# (pos,pState) \t= getPosition pState\n\t\t (filename,pState=:{ps_error={pea_file,pea_ok}})\t= getFilename pState\n\t\t pea_file \t= \tpea_file\n\t\t \t\t\t\t<<< \"Parse warning [\"\n\t\t \t\t\t\t<<< filename <<< \",\"\n\t\t \t\t\t\t<<< pos \n\t\t \t\t\t\t<<< (if (size act > 0) (\",\" + act) \"\") <<< \"]: \"\n\t\t \t\t\t\t<<< msg\n\t\t \t\t\t\t<<< \"\\n\"\n\t\t=\t{ pState\n\t\t\t& ps_error\t\t= { pea_file = pea_file, pea_ok = pea_ok }\n\t\t\t}\n\nparseError :: !{# Char} !(Optional Token) !{# Char} !ParseState -> ParseState\nparseError act opt_token msg pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t= pState\n\t| otherwise \/\/ not pState.ps_skipping\n\t\t# (pos,pState) \t= getPosition pState\n\t\t (filename,pState=:{ps_error={pea_file}})\t= getFilename pState\n\t\t pea_file \t= \tpea_file\n\t\t \t\t\t\t<<< \"Parse error [\"\n\t\t \t\t\t\t<<< filename <<< \",\"\n\t\t \t\t\t\t<<< pos \n\t\t \t\t\t\t<<< (if (size act > 0) (\",\" + act) \"\") <<< \"]: \"\n\t\t \t\t\t\t<<< msg\n\t\t pea_file\t= case opt_token of\n\t\t \t\t\t\tYes token\t-> pea_file <<< \" expected instead of \" <<< token <<< \"\\n\"\n\t\t \t\t\t\tNo\t\t\t-> pea_file <<< \" expected\\n\"\n\t\t pState \t=\t{ pState\n\t\t\t\t\t\t& ps_flags = pState.ps_flags bitor PS_SkippingMask\n\t\t\t\t\t\t, ps_error = { pea_file = pea_file, pea_ok = False }\n\t\t\t\t\t\t}\n\t\t= case opt_token of\n\t\t\tYes _\t-> tokenBack pState\n\t\t\tNo\t\t-> pState\n\nparseErrorSimple :: !{# Char} !{# Char} !ParseState -> ParseState\nparseErrorSimple act msg pState\n\t| pState.ps_flags bitand PS_SkippingMask<>0\n\t\t= pState\n\t| otherwise \/\/ not pState.ps_skipping\n\t\t# (pos,pState) \t= getPosition pState\n\t\t (filename,pState=:{ps_error={pea_file}})\t= getFilename pState\n\t\t pea_file \t= \tpea_file\n\t\t \t\t\t\t<<< \"Parse error [\"\n\t\t \t\t\t\t<<< filename <<< \",\"\n\t\t \t\t\t\t<<< pos \n\t\t \t\t\t\t<<< (if (size act > 0) (\",\" + act) \"\") <<< \"]: \"\n\t\t \t\t\t\t<<< msg\n\t\t \t\t\t\t<<< '\\n'\n\t\t= { pState\t& ps_flags = pState.ps_flags bitor PS_SkippingMask\n\t\t\t\t\t, ps_error = { pea_file = pea_file, pea_ok = False }\n\t\t }\n\ngetFileAndLineNr :: !ParseState -> (!String, !Int, !ParseState)\ngetFileAndLineNr pState =: {ps_scanState}\n\t# (filename,scanState)\t= getFilename ps_scanState\n\t ({fp_line},scanState)\t= getPosition scanState\n\t= (filename, fp_line, {pState & ps_scanState = scanState} )\n\n\/*\n\tSimple parse functions\n*\/\n\nwantToken :: !ScanContext !{#Char} !Token !ParseState -> ParseState\nwantToken scanContext act dem_token pState\n\t# (token, pState) = nextToken scanContext pState\n\t| dem_token == token\n\t\t= pState\n\t\t= parseError act (Yes token) (toString dem_token) pState\n\ninstance want Priority\nwhere\n\twant pState\n\t\t# (token, pState) = nextToken FunctionContext pState\n\t\t= case token of\n\t\t\tPriorityToken prio\n\t\t\t\t-> (prio, pState)\n\t\t\t_\n\t\t\t\t-> (NoPrio, parseError \"Priority\" (Yes token) \"with\" pState)\n\ninstance want {# Char}\nwhere\n\twant pState\n\t\t# (token, pState) = nextToken GeneralContext pState\n\t\t= case token of\n\t\t\tIdentToken name -> (name, pState)\n\t\t\t_\t\t\t\t-> (\"\", parseError \"String\" (Yes token) \"identifier\" pState)\n\nwantModuleName :: !*ParseState -> (!{# Char}, !*ParseState)\nwantModuleName pState\n\t# (token, pState) = nextToken ModuleNameContext pState\n\t= case token of\n\t\tIdentToken name -> (name, pState)\n\t\tUnderscoreIdentToken name -> (name, pState)\n\t\t_\t\t\t\t-> (\"\", parseError \"String\" (Yes token) \"module name\" pState)\n\nwantOptionalQualifiedAndModuleName :: !*ParseState -> (!ImportQualified,!{#Char},!*ParseState)\nwantOptionalQualifiedAndModuleName pState\n\t# (token, pState) = nextToken ModuleNameContext pState\n\t= case token of\n\t\tIdentToken name1=:\"qualified\"\n\t\t\t# (token, pState) = nextToken ModuleNameContext pState\n\t\t\t-> case token of\n\t\t\t\tIdentToken name\n\t\t\t\t\t-> (Qualified, name, pState)\n\t\t\t\tUnderscoreIdentToken name\n\t\t\t\t\t-> (Qualified, name, pState)\n\t\t\t\tQualifiedIdentToken module_dname module_fname\n\t\t\t\t\t-> (Qualified, module_dname+++\".\"+++module_fname, pState)\n\t\t\t\t_\n\t\t\t\t\t-> (NotQualified, name1, tokenBack pState)\n\t\tIdentToken name\t\n\t\t\t-> (NotQualified, name, pState)\n\t\tUnderscoreIdentToken name\n\t\t\t-> (NotQualified, name, pState)\n\t\tQualifiedIdentToken module_dname module_fname\n\t\t\t-> (NotQualified, module_dname+++\".\"+++module_fname, pState)\n\t\t_\n\t\t\t-> (NotQualified, \"\", parseError \"String\" (Yes token) \"module name\" pState)\n\ntryTypeVar :: !ParseState -> (!Bool, TypeVar, !ParseState)\ntryTypeVar pState\n\t# (token, pState) = nextToken TypeContext pState\n\t= tryTypeVarT token pState\n\ntryTypeVarT :: !Token !ParseState -> (!Bool, TypeVar, !ParseState)\ntryTypeVarT (IdentToken name) pState\n\t| isLowerCaseName name\n\t\t# (id, pState) = stringToIdent name IC_Type pState\n\t\t= (True, MakeTypeVar id, pState)\n\t\t= (False, abort \"no UC ident\", tokenBack pState)\ntryTypeVarT token pState\n\t\t= (False, abort \"no type variable\", tokenBack pState)\n\nwantUpperCaseName :: !String !ParseState -> (!String, !ParseState)\nwantUpperCaseName string pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tIdentToken name \n\t\t\t| isUpperCaseName name\n\t\t\t\t-> (name, pState)\n\t\t_\t-> (\"dummy uppercase name\", parseError string (Yes token) \"upper case ident\" pState)\n\/*\nwantNonUpperCaseName :: !String !ParseState -> (!String, !ParseState)\nwantNonUpperCaseName string pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tIdentToken name \n\t\t\t| ~ (isUpperCaseName name)\n\t\t\t\t-> (name, pState)\n\t\t_\t-> (\"dummy non uppercase name\", parseError string (Yes token) \"non upper case ident\" pState)\n*\/\nwantLowerCaseName :: !String !ParseState -> (!String, !ParseState)\nwantLowerCaseName string pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tIdentToken name \n\t\t\t| isLowerCaseName name\n\t\t\t\t-> (name, pState)\n\t\t_\n\t\t\t-> (\"dummy lowercase name\", parseError string (Yes token) \"lower case ident\" pState)\n\nwantConstructorName :: !String !ParseState -> (!String, !ParseState)\nwantConstructorName string pState\n\t# (token, pState) = nextToken GeneralContext pState\n\t= case token of\n\t\tIdentToken name \n\t\t\t| isUpperCaseName name || isFunnyIdName name\n\t\t\t\t-> (name, pState)\n\t\t_\n\t\t\t-> (\"\", parseError string (Yes token) \"upper case ident\" pState)\n\nisDefinesFieldToken :: ! Token -> Bool\nisDefinesFieldToken EqualToken = True\nisDefinesFieldToken CurlyCloseToken = True\nisDefinesFieldToken CommaToken = True\nisDefinesFieldToken token = False\n\n \/\/---------------\/\/\n \/\/--- Tracing ---\/\/\n\/\/---------------\/\/\n\n(-->>) val _ :== val\n\/\/(-->>) val message :== val ---> (\"Parser\",message)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"ddf4cad21f9bd05a526d0440c1612798baa88b71","subject":"fix problem with : for longer strings","message":"fix problem with : for longer strings\n","repos":"clean-cloogle\/clean-irc","old_file":"IRC.icl","new_file":"IRC.icl","new_contents":"implementation module IRC\n\nimport StdList\nimport GenPrint\nimport StdOverloaded\nimport Data.Maybe\nimport Data.Either\nimport StdFunc\nimport StdString\nfrom Text import class Text(..), instance Text String\nfrom StdMisc import undef\n\nderive gPrint IRCCommands, IRCReplies, IRCErrors, (,), Maybe, (), Either\n\ninstance toString IRCCommands where\n\ttoString r = flip (+++) \"\\r\\n\" case r of\n\t\/\/ADMIN (Maybe String)\n\t\/\/AWAY String\n\t\/\/CONNECT String Int (Maybe String)\n\t\/\/DIE \n\t\/\/ERROR String\n\t\/\/INFO (Maybe String)\n\t\/\/INVITE String String\n\t\/\/ISON [String]\n\t\tJOIN chs = \"JOIN \" +++ (if (isEmpty chs) \"0\"\n\t\t\t(join \", \" [join \" \" [ch:maybeToList mk]\\\\(ch, mk)<-chs]))\n\t\/\/KICK String String (Maybe String)\n\t\/\/KILL String String\n\t\/\/LINKS (Maybe (Maybe String, String))\n\t\/\/LIST [String]\n\t\/\/LUSERS (Maybe (String, Maybe String))\n\t\/\/MODE String\n\t\/\/MOTD (Maybe String)\n\t\/\/NAMES [String]\n\t\tNICK n = join \" \" [\"NICK\", n]\n\t\/\/NJOIN \n\t\/\/NOTICE String String\n\t\/\/OPER String String \n\t\/\/PART [String]\n\t\/\/PASS String\n\t\/\/PING [String]\n\t\/\/PONG [String]\n\t\tPRIVMSG dest msg = join \" \" [\"PRIVMSG\", dest, \":\"+++msg]\n\t\tQUIT msg = join \" \" [\"QUIT\":maybeToList msg]\n\t\/\/REHASH \n\t\/\/RESTART \n\t\/\/SERVER \n\t\/\/SERVICE String String String String\n\t\/\/SERVLIST (Maybe (String, Maybe String))\n\t\/\/SQUERY String String\n\t\/\/SQUIRT \n\t\/\/SQUIT String String\n\t\/\/STATS (Maybe (String, Maybe String))\n\t\/\/SUMMON String (Maybe (String, Maybe String))\n\t\/\/TIME (Maybe String)\n\t\/\/TOPIC String (Maybe String)\n\t\/\/TRACE (Maybe String)\n\t\tUSER login mode rn = join \" \" [\"USER\", login, toString mode, \"*\", \":\"+++rn]\n\t\/\/USERHOST [String]\n\t\/\/USERS (Maybe String)\n\t\/\/VERSION (Maybe String)\n\t\/\/WALLOPS String\n\t\/\/WHO (Maybe String)\n\t\/\/WHOIS (Maybe String) [String]\n\t\/\/WHOWAS (Maybe String) [String]\n\t\t_ = printToString r\n\n\ninstance toString IRCReplies where toString r = printToString r\ninstance toString IRCErrors where toString r = printToString r\n\ninstance fromInt IRCReplies where\n\tfromInt r = case r of \n\t\t1 = RPL_WELCOME\n\t\t2 = RPL_YOURHOST\n\t\t3 = RPL_CREATED\n\t\t4 = RPL_MYINFO\n\t\t5 = RPL_BOUNCE\n\t\t200 = RPL_TRACELINK\n\t\t201 = RPL_TRACECONNECTING\n\t\t202 = RPL_TRACEHANDSHAKE\n\t\t203 = RPL_TRACEUNKNOWN\n\t\t204 = RPL_TRACEOPERATOR\n\t\t205 = RPL_TRACEUSER\n\t\t206 = RPL_TRACESERVER\n\t\t207 = RPL_TRACESERVICE\n\t\t208 = RPL_TRACENEWTYPE\n\t\t209 = RPL_TRACECLASS\n\t\t210 = RPL_TRACERECONNECT\n\t\t211 = RPL_STATSLINKINFO\n\t\t212 = RPL_STATSCOMMANDS\n\t\t219 = RPL_ENDOFSTATS\n\t\t221 = RPL_UMODEIS\n\t\t234 = RPL_SERVLIST\n\t\t235 = RPL_SERVLISTEND\n\t\t242 = RPL_STATSUPTIME\n\t\t243 = RPL_STATSOLINE\n\t\t251 = RPL_LUSERCLIENT\n\t\t252 = RPL_LUSEROP\n\t\t253 = RPL_LUSERUNKNOWN\n\t\t254 = RPL_LUSERCHANNELS\n\t\t255 = RPL_LUSERME\n\t\t256 = RPL_ADMINME\n\t\t257 = RPL_ADMINLOC1\n\t\t258 = RPL_ADMINLOC2\n\t\t259 = RPL_ADMINEMAIL\n\t\t261 = RPL_TRACELOG\n\t\t262 = RPL_TRACEEND\n\t\t263 = RPL_TRYAGAIN\n\t\t301 = RPL_AWAY\n\t\t302 = RPL_USERHOST\n\t\t303 = RPL_ISON\n\t\t304 = RPL_UNAWAY\n\t\t305 = RPL_NOWAWAY\n\t\t311 = RPL_WHOISUSER\n\t\t312 = RPL_WHOISSERVER\n\t\t313 = RPL_WHOISOPERATOR\n\t\t314 = RPL_WHOWASUSER\n\t\t315 = RPL_ENDOFWHO\n\t\t317 = RPL_WHOISIDLE\n\t\t318 = RPL_ENDOFWHOIS\n\t\t319 = RPL_WHOISCHANNELS\n\t\t321 = RPL_LISTSTART\n\t\t322 = RPL_LIST\n\t\t323 = RPL_LISTEND\n\t\t324 = RPL_CHANNELMODEIS\n\t\t325 = RPL_UNIQOPIS\n\t\t331 = RPL_NOTOPIC\n\t\t332 = RPL_TOPIC\n\t\t341 = RPL_INVITING\n\t\t342 = RPL_SUMMONING\n\t\t346 = RPL_INVITELIST\n\t\t347 = RPL_ENDOFINVITELIST\n\t\t348 = RPL_EXCEPTLIST\n\t\t349 = RPL_ENDOFEXCEPTLIST\n\t\t351 = RPL_VERSION\n\t\t352 = RPL_WHOREPLY\n\t\t353 = RPL_NAMREPLY\n\t\t364 = RPL_LINKS\n\t\t365 = RPL_ENDOFLINKS\n\t\t366 = RPL_ENDOFNAMES\n\t\t367 = RPL_BANLIST\n\t\t368 = RPL_ENDOFBANLIST\n\t\t369 = RPL_ENDOFWHOWAS\n\t\t371 = RPL_INFO\n\t\t372 = RPL_MOTD\n\t\t374 = RPL_ENDOFINFO\n\t\t375 = RPL_MOTDSTART\n\t\t376 = RPL_ENDOFMOTD\n\t\t381 = RPL_YOUREOPER\n\t\t382 = RPL_REHASHING\n\t\t383 = RPL_YOURESERVICE\n\t\t391 = RPL_TIME\n\t\t392 = RPL_USERSSTART\n\t\t393 = RPL_USERS\n\t\t394 = RPL_ENDOFUSERS\n\t\t395 = RPL_NOUSERS\n\t\t_ = undef\n\ninstance toInt IRCReplies where\n\ttoInt r = case r of \n\t\tRPL_WELCOME = 1\n\t\tRPL_YOURHOST = 2\n\t\tRPL_CREATED = 3\n\t\tRPL_MYINFO = 4\n\t\tRPL_BOUNCE = 5\n\t\tRPL_TRACELINK = 200\n\t\tRPL_TRACECONNECTING = 201\n\t\tRPL_TRACEHANDSHAKE = 202\n\t\tRPL_TRACEUNKNOWN = 203\n\t\tRPL_TRACEOPERATOR = 204\n\t\tRPL_TRACEUSER = 205\n\t\tRPL_TRACESERVER = 206\n\t\tRPL_TRACESERVICE = 207\n\t\tRPL_TRACENEWTYPE = 208\n\t\tRPL_TRACECLASS = 209\n\t\tRPL_TRACERECONNECT = 210\n\t\tRPL_STATSLINKINFO = 211\n\t\tRPL_STATSCOMMANDS = 212\n\t\tRPL_ENDOFSTATS = 219\n\t\tRPL_UMODEIS = 221\n\t\tRPL_SERVLIST = 234\n\t\tRPL_SERVLISTEND = 234\n\t\tRPL_STATSUPTIME = 242\n\t\tRPL_STATSOLINE = 243\n\t\tRPL_LUSERCLIENT = 251\n\t\tRPL_LUSEROP = 252\n\t\tRPL_LUSERUNKNOWN = 253\n\t\tRPL_LUSERCHANNELS = 254\n\t\tRPL_LUSERME = 255\n\t\tRPL_ADMINME = 256\n\t\tRPL_ADMINLOC1 = 257\n\t\tRPL_ADMINLOC2 = 258\n\t\tRPL_ADMINEMAIL = 259\n\t\tRPL_TRACELOG = 261\n\t\tRPL_TRACEEND = 262\n\t\tRPL_TRYAGAIN = 263\n\t\tRPL_AWAY = 301\n\t\tRPL_USERHOST = 302\n\t\tRPL_ISON = 303\n\t\tRPL_UNAWAY = 304\n\t\tRPL_NOWAWAY = 305\n\t\tRPL_WHOISUSER = 311\n\t\tRPL_WHOISSERVER = 312\n\t\tRPL_WHOISOPERATOR = 313\n\t\tRPL_WHOWASUSER = 314\n\t\tRPL_ENDOFWHO = 315\n\t\tRPL_WHOISIDLE = 317\n\t\tRPL_ENDOFWHOIS = 318\n\t\tRPL_WHOISCHANNELS = 319\n\t\tRPL_LISTSTART = 321\n\t\tRPL_LIST = 322\n\t\tRPL_LISTEND = 323\n\t\tRPL_CHANNELMODEIS = 324\n\t\tRPL_UNIQOPIS = 325\n\t\tRPL_NOTOPIC = 331\n\t\tRPL_TOPIC = 332\n\t\tRPL_INVITING = 341\n\t\tRPL_SUMMONING = 342\n\t\tRPL_INVITELIST = 346\n\t\tRPL_ENDOFINVITELIST = 347\n\t\tRPL_EXCEPTLIST = 348\n\t\tRPL_ENDOFEXCEPTLIST = 349\n\t\tRPL_VERSION = 351\n\t\tRPL_WHOREPLY = 352\n\t\tRPL_NAMREPLY = 353\n\t\tRPL_LINKS = 364\n\t\tRPL_ENDOFLINKS = 365\n\t\tRPL_ENDOFNAMES = 366\n\t\tRPL_BANLIST = 367\n\t\tRPL_ENDOFBANLIST = 367\n\t\tRPL_ENDOFWHOWAS = 369\n\t\tRPL_INFO = 371\n\t\tRPL_MOTD = 372\n\t\tRPL_ENDOFINFO = 374\n\t\tRPL_MOTDSTART = 375\n\t\tRPL_ENDOFMOTD = 376\n\t\tRPL_YOUREOPER = 381\n\t\tRPL_REHASHING = 382\n\t\tRPL_YOURESERVICE = 383\n\t\tRPL_TIME = 391\n\t\tRPL_USERSSTART = 392\n\t\tRPL_USERS = 393\n\t\tRPL_ENDOFUSERS = 394\n\t\tRPL_NOUSERS = 395\n\ninstance fromInt IRCErrors where\n\tfromInt r = case r of\n\t\t401 = ERR_NOSUCHNICK\n\t\t402 = ERR_NOSUCHSERVER\n\t\t403 = ERR_NOSUCHCHANNEL\n\t\t404 = ERR_CANNOTSENDTOCHAN\n\t\t405 = ERR_TOOMANYCHANNELS\n\t\t406 = ERR_WASNOSUCHNICK\n\t\t407 = ERR_TOOMANYTARGETS\n\t\t408 = ERR_NOSUCHSERVICE\n\t\t409 = ERR_NOORIGIN\n\t\t411 = ERR_NORECIPIENT\n\t\t412 = ERR_NOTEXTTOSEND\n\t\t413 = ERR_NOTOPLEVEL\n\t\t414 = ERR_WILDTOPLEVEL\n\t\t415 = ERR_BADMASK\n\t\t421 = ERR_UNKNOWNCOMMAND\n\t\t422 = ERR_NOMOTD\n\t\t423 = ERR_NOADMININFO\n\t\t424 = ERR_FILEERROR\n\t\t431 = ERR_NONICKNAMEGIVEN\n\t\t432 = ERR_ERRONEUSNICKNAME\n\t\t433 = ERR_NICKNAMEINUSE\n\t\t436 = ERR_NICKCOLLISION\n\t\t437 = ERR_UNAVAILRESOURCE\n\t\t441 = ERR_USERNOTINCHANNEL\n\t\t442 = ERR_NOTONCHANNEL\n\t\t443 = ERR_USERONCHANNEL\n\t\t444 = ERR_NOLOGIN\n\t\t445 = ERR_SUMMONDISABLED\n\t\t446 = ERR_USERSDISABLED\n\t\t451 = ERR_NOTREGISTERED\n\t\t461 = ERR_NEEDMOREPARAMS\n\t\t462 = ERR_ALREADYREGISTRED\n\t\t463 = ERR_NOPERMFORHOST\n\t\t464 = ERR_PASSWDMISMATCH\n\t\t465 = ERR_YOUREBANNEDCREEP\n\t\t466 = ERR_YOUWILLBEBANNED\n\t\t467 = ERR_KEYSET\n\t\t471 = ERR_CHANNELISFULL\n\t\t472 = ERR_UNKNOWNMODE\n\t\t473 = ERR_INVITEONLYCHAN\n\t\t474 = ERR_BANNEDFROMCHAN\n\t\t475 = ERR_BADCHANNELKEY\n\t\t476 = ERR_BADCHANMASK\n\t\t477 = ERR_NOCHANMODES\n\t\t478 = ERR_BANLISTFULL\n\t\t481 = ERR_NOPRIVILEGES\n\t\t482 = ERR_CHANOPRIVSNEEDED\n\t\t483 = ERR_CANTKILLSERVER\n\t\t484 = ERR_RESTRICTED\n\t\t485 = ERR_UNIQOPPRIVSNEEDED\n\t\t491 = ERR_NOOPERHOST\n\t\t501 = ERR_UMODEUNKNOWNFLAG\n\t\t502 = ERR_USERSDONTMATCH\n\ninstance toInt IRCErrors where\n\ttoInt r = case r of\n\t\tERR_NOSUCHNICK = 401\n\t\tERR_NOSUCHSERVER = 402\n\t\tERR_NOSUCHCHANNEL = 403\n\t\tERR_CANNOTSENDTOCHAN = 404\n\t\tERR_TOOMANYCHANNELS = 405\n\t\tERR_WASNOSUCHNICK = 406\n\t\tERR_TOOMANYTARGETS = 407\n\t\tERR_NOSUCHSERVICE = 408\n\t\tERR_NOORIGIN = 409\n\t\tERR_NORECIPIENT = 411\n\t\tERR_NOTEXTTOSEND = 412\n\t\tERR_NOTOPLEVEL = 413\n\t\tERR_WILDTOPLEVEL = 414\n\t\tERR_BADMASK = 415\n\t\tERR_UNKNOWNCOMMAND = 421\n\t\tERR_NOMOTD = 422\n\t\tERR_NOADMININFO = 423\n\t\tERR_FILEERROR = 424\n\t\tERR_NONICKNAMEGIVEN = 431\n\t\tERR_ERRONEUSNICKNAME = 432\n\t\tERR_NICKNAMEINUSE = 433\n\t\tERR_NICKCOLLISION = 436\n\t\tERR_UNAVAILRESOURCE = 437\n\t\tERR_USERNOTINCHANNEL = 441\n\t\tERR_NOTONCHANNEL = 442\n\t\tERR_USERONCHANNEL = 443\n\t\tERR_NOLOGIN = 444\n\t\tERR_SUMMONDISABLED = 445\n\t\tERR_USERSDISABLED = 446\n\t\tERR_NOTREGISTERED = 451\n\t\tERR_NEEDMOREPARAMS = 461\n\t\tERR_ALREADYREGISTRED = 462\n\t\tERR_NOPERMFORHOST = 463\n\t\tERR_PASSWDMISMATCH = 464\n\t\tERR_YOUREBANNEDCREEP = 465\n\t\tERR_YOUWILLBEBANNED = 466\n\t\tERR_KEYSET = 467\n\t\tERR_CHANNELISFULL = 471\n\t\tERR_UNKNOWNMODE = 472\n\t\tERR_INVITEONLYCHAN = 473\n\t\tERR_BANNEDFROMCHAN = 474\n\t\tERR_BADCHANNELKEY = 475\n\t\tERR_BADCHANMASK = 476\n\t\tERR_NOCHANMODES = 477\n\t\tERR_BANLISTFULL = 478\n\t\tERR_NOPRIVILEGES = 481\n\t\tERR_CHANOPRIVSNEEDED = 482\n\t\tERR_CANTKILLSERVER = 483\n\t\tERR_RESTRICTED = 484\n\t\tERR_UNIQOPPRIVSNEEDED = 485\n\t\tERR_NOOPERHOST = 491\n\t\tERR_UMODEUNKNOWNFLAG = 501\n\t\tERR_USERSDONTMATCH = 502\n","old_contents":"implementation module IRC\n\nimport StdList\nimport GenPrint\nimport StdOverloaded\nimport Data.Maybe\nimport Data.Either\nimport StdFunc\nimport StdString\nfrom Text import class Text(..), instance Text String\nfrom StdMisc import undef\n\nderive gPrint IRCCommands, IRCReplies, IRCErrors, (,), Maybe, (), Either\n\ninstance toString IRCCommands where\n\ttoString r = flip (+++) \"\\r\\n\" case r of\n\t\/\/ADMIN (Maybe String)\n\t\/\/AWAY String\n\t\/\/CONNECT String Int (Maybe String)\n\t\/\/DIE \n\t\/\/ERROR String\n\t\/\/INFO (Maybe String)\n\t\/\/INVITE String String\n\t\/\/ISON [String]\n\t\tJOIN chs = \"JOIN \" +++ (if (isEmpty chs) \"0\"\n\t\t\t(join \", \" [join \" \" [ch:maybeToList mk]\\\\(ch, mk)<-chs]))\n\t\/\/KICK String String (Maybe String)\n\t\/\/KILL String String\n\t\/\/LINKS (Maybe (Maybe String, String))\n\t\/\/LIST [String]\n\t\/\/LUSERS (Maybe (String, Maybe String))\n\t\/\/MODE String\n\t\/\/MOTD (Maybe String)\n\t\/\/NAMES [String]\n\t\tNICK n = join \" \" [\"NICK\", n]\n\t\/\/NJOIN \n\t\/\/NOTICE String String\n\t\/\/OPER String String \n\t\/\/PART [String]\n\t\/\/PASS String\n\t\/\/PING [String]\n\t\/\/PONG [String]\n\t\tPRIVMSG dest msg = join \" \" [\"PRIVMSG\", dest, msg]\n\t\tQUIT msg = join \" \" [\"QUIT\":maybeToList msg]\n\t\/\/REHASH \n\t\/\/RESTART \n\t\/\/SERVER \n\t\/\/SERVICE String String String String\n\t\/\/SERVLIST (Maybe (String, Maybe String))\n\t\/\/SQUERY String String\n\t\/\/SQUIRT \n\t\/\/SQUIT String String\n\t\/\/STATS (Maybe (String, Maybe String))\n\t\/\/SUMMON String (Maybe (String, Maybe String))\n\t\/\/TIME (Maybe String)\n\t\/\/TOPIC String (Maybe String)\n\t\/\/TRACE (Maybe String)\n\t\tUSER login mode rn = join \" \" [\"USER\", login, toString mode, \"*\", \":\", rn]\n\t\/\/USERHOST [String]\n\t\/\/USERS (Maybe String)\n\t\/\/VERSION (Maybe String)\n\t\/\/WALLOPS String\n\t\/\/WHO (Maybe String)\n\t\/\/WHOIS (Maybe String) [String]\n\t\/\/WHOWAS (Maybe String) [String]\n\t\t_ = printToString r\n\n\ninstance toString IRCReplies where toString r = printToString r\ninstance toString IRCErrors where toString r = printToString r\n\ninstance fromInt IRCReplies where\n\tfromInt r = case r of \n\t\t1 = RPL_WELCOME\n\t\t2 = RPL_YOURHOST\n\t\t3 = RPL_CREATED\n\t\t4 = RPL_MYINFO\n\t\t5 = RPL_BOUNCE\n\t\t200 = RPL_TRACELINK\n\t\t201 = RPL_TRACECONNECTING\n\t\t202 = RPL_TRACEHANDSHAKE\n\t\t203 = RPL_TRACEUNKNOWN\n\t\t204 = RPL_TRACEOPERATOR\n\t\t205 = RPL_TRACEUSER\n\t\t206 = RPL_TRACESERVER\n\t\t207 = RPL_TRACESERVICE\n\t\t208 = RPL_TRACENEWTYPE\n\t\t209 = RPL_TRACECLASS\n\t\t210 = RPL_TRACERECONNECT\n\t\t211 = RPL_STATSLINKINFO\n\t\t212 = RPL_STATSCOMMANDS\n\t\t219 = RPL_ENDOFSTATS\n\t\t221 = RPL_UMODEIS\n\t\t234 = RPL_SERVLIST\n\t\t235 = RPL_SERVLISTEND\n\t\t242 = RPL_STATSUPTIME\n\t\t243 = RPL_STATSOLINE\n\t\t251 = RPL_LUSERCLIENT\n\t\t252 = RPL_LUSEROP\n\t\t253 = RPL_LUSERUNKNOWN\n\t\t254 = RPL_LUSERCHANNELS\n\t\t255 = RPL_LUSERME\n\t\t256 = RPL_ADMINME\n\t\t257 = RPL_ADMINLOC1\n\t\t258 = RPL_ADMINLOC2\n\t\t259 = RPL_ADMINEMAIL\n\t\t261 = RPL_TRACELOG\n\t\t262 = RPL_TRACEEND\n\t\t263 = RPL_TRYAGAIN\n\t\t301 = RPL_AWAY\n\t\t302 = RPL_USERHOST\n\t\t303 = RPL_ISON\n\t\t304 = RPL_UNAWAY\n\t\t305 = RPL_NOWAWAY\n\t\t311 = RPL_WHOISUSER\n\t\t312 = RPL_WHOISSERVER\n\t\t313 = RPL_WHOISOPERATOR\n\t\t314 = RPL_WHOWASUSER\n\t\t315 = RPL_ENDOFWHO\n\t\t317 = RPL_WHOISIDLE\n\t\t318 = RPL_ENDOFWHOIS\n\t\t319 = RPL_WHOISCHANNELS\n\t\t321 = RPL_LISTSTART\n\t\t322 = RPL_LIST\n\t\t323 = RPL_LISTEND\n\t\t324 = RPL_CHANNELMODEIS\n\t\t325 = RPL_UNIQOPIS\n\t\t331 = RPL_NOTOPIC\n\t\t332 = RPL_TOPIC\n\t\t341 = RPL_INVITING\n\t\t342 = RPL_SUMMONING\n\t\t346 = RPL_INVITELIST\n\t\t347 = RPL_ENDOFINVITELIST\n\t\t348 = RPL_EXCEPTLIST\n\t\t349 = RPL_ENDOFEXCEPTLIST\n\t\t351 = RPL_VERSION\n\t\t352 = RPL_WHOREPLY\n\t\t353 = RPL_NAMREPLY\n\t\t364 = RPL_LINKS\n\t\t365 = RPL_ENDOFLINKS\n\t\t366 = RPL_ENDOFNAMES\n\t\t367 = RPL_BANLIST\n\t\t368 = RPL_ENDOFBANLIST\n\t\t369 = RPL_ENDOFWHOWAS\n\t\t371 = RPL_INFO\n\t\t372 = RPL_MOTD\n\t\t374 = RPL_ENDOFINFO\n\t\t375 = RPL_MOTDSTART\n\t\t376 = RPL_ENDOFMOTD\n\t\t381 = RPL_YOUREOPER\n\t\t382 = RPL_REHASHING\n\t\t383 = RPL_YOURESERVICE\n\t\t391 = RPL_TIME\n\t\t392 = RPL_USERSSTART\n\t\t393 = RPL_USERS\n\t\t394 = RPL_ENDOFUSERS\n\t\t395 = RPL_NOUSERS\n\t\t_ = undef\n\ninstance toInt IRCReplies where\n\ttoInt r = case r of \n\t\tRPL_WELCOME = 1\n\t\tRPL_YOURHOST = 2\n\t\tRPL_CREATED = 3\n\t\tRPL_MYINFO = 4\n\t\tRPL_BOUNCE = 5\n\t\tRPL_TRACELINK = 200\n\t\tRPL_TRACECONNECTING = 201\n\t\tRPL_TRACEHANDSHAKE = 202\n\t\tRPL_TRACEUNKNOWN = 203\n\t\tRPL_TRACEOPERATOR = 204\n\t\tRPL_TRACEUSER = 205\n\t\tRPL_TRACESERVER = 206\n\t\tRPL_TRACESERVICE = 207\n\t\tRPL_TRACENEWTYPE = 208\n\t\tRPL_TRACECLASS = 209\n\t\tRPL_TRACERECONNECT = 210\n\t\tRPL_STATSLINKINFO = 211\n\t\tRPL_STATSCOMMANDS = 212\n\t\tRPL_ENDOFSTATS = 219\n\t\tRPL_UMODEIS = 221\n\t\tRPL_SERVLIST = 234\n\t\tRPL_SERVLISTEND = 234\n\t\tRPL_STATSUPTIME = 242\n\t\tRPL_STATSOLINE = 243\n\t\tRPL_LUSERCLIENT = 251\n\t\tRPL_LUSEROP = 252\n\t\tRPL_LUSERUNKNOWN = 253\n\t\tRPL_LUSERCHANNELS = 254\n\t\tRPL_LUSERME = 255\n\t\tRPL_ADMINME = 256\n\t\tRPL_ADMINLOC1 = 257\n\t\tRPL_ADMINLOC2 = 258\n\t\tRPL_ADMINEMAIL = 259\n\t\tRPL_TRACELOG = 261\n\t\tRPL_TRACEEND = 262\n\t\tRPL_TRYAGAIN = 263\n\t\tRPL_AWAY = 301\n\t\tRPL_USERHOST = 302\n\t\tRPL_ISON = 303\n\t\tRPL_UNAWAY = 304\n\t\tRPL_NOWAWAY = 305\n\t\tRPL_WHOISUSER = 311\n\t\tRPL_WHOISSERVER = 312\n\t\tRPL_WHOISOPERATOR = 313\n\t\tRPL_WHOWASUSER = 314\n\t\tRPL_ENDOFWHO = 315\n\t\tRPL_WHOISIDLE = 317\n\t\tRPL_ENDOFWHOIS = 318\n\t\tRPL_WHOISCHANNELS = 319\n\t\tRPL_LISTSTART = 321\n\t\tRPL_LIST = 322\n\t\tRPL_LISTEND = 323\n\t\tRPL_CHANNELMODEIS = 324\n\t\tRPL_UNIQOPIS = 325\n\t\tRPL_NOTOPIC = 331\n\t\tRPL_TOPIC = 332\n\t\tRPL_INVITING = 341\n\t\tRPL_SUMMONING = 342\n\t\tRPL_INVITELIST = 346\n\t\tRPL_ENDOFINVITELIST = 347\n\t\tRPL_EXCEPTLIST = 348\n\t\tRPL_ENDOFEXCEPTLIST = 349\n\t\tRPL_VERSION = 351\n\t\tRPL_WHOREPLY = 352\n\t\tRPL_NAMREPLY = 353\n\t\tRPL_LINKS = 364\n\t\tRPL_ENDOFLINKS = 365\n\t\tRPL_ENDOFNAMES = 366\n\t\tRPL_BANLIST = 367\n\t\tRPL_ENDOFBANLIST = 367\n\t\tRPL_ENDOFWHOWAS = 369\n\t\tRPL_INFO = 371\n\t\tRPL_MOTD = 372\n\t\tRPL_ENDOFINFO = 374\n\t\tRPL_MOTDSTART = 375\n\t\tRPL_ENDOFMOTD = 376\n\t\tRPL_YOUREOPER = 381\n\t\tRPL_REHASHING = 382\n\t\tRPL_YOURESERVICE = 383\n\t\tRPL_TIME = 391\n\t\tRPL_USERSSTART = 392\n\t\tRPL_USERS = 393\n\t\tRPL_ENDOFUSERS = 394\n\t\tRPL_NOUSERS = 395\n\ninstance fromInt IRCErrors where\n\tfromInt r = case r of\n\t\t401 = ERR_NOSUCHNICK\n\t\t402 = ERR_NOSUCHSERVER\n\t\t403 = ERR_NOSUCHCHANNEL\n\t\t404 = ERR_CANNOTSENDTOCHAN\n\t\t405 = ERR_TOOMANYCHANNELS\n\t\t406 = ERR_WASNOSUCHNICK\n\t\t407 = ERR_TOOMANYTARGETS\n\t\t408 = ERR_NOSUCHSERVICE\n\t\t409 = ERR_NOORIGIN\n\t\t411 = ERR_NORECIPIENT\n\t\t412 = ERR_NOTEXTTOSEND\n\t\t413 = ERR_NOTOPLEVEL\n\t\t414 = ERR_WILDTOPLEVEL\n\t\t415 = ERR_BADMASK\n\t\t421 = ERR_UNKNOWNCOMMAND\n\t\t422 = ERR_NOMOTD\n\t\t423 = ERR_NOADMININFO\n\t\t424 = ERR_FILEERROR\n\t\t431 = ERR_NONICKNAMEGIVEN\n\t\t432 = ERR_ERRONEUSNICKNAME\n\t\t433 = ERR_NICKNAMEINUSE\n\t\t436 = ERR_NICKCOLLISION\n\t\t437 = ERR_UNAVAILRESOURCE\n\t\t441 = ERR_USERNOTINCHANNEL\n\t\t442 = ERR_NOTONCHANNEL\n\t\t443 = ERR_USERONCHANNEL\n\t\t444 = ERR_NOLOGIN\n\t\t445 = ERR_SUMMONDISABLED\n\t\t446 = ERR_USERSDISABLED\n\t\t451 = ERR_NOTREGISTERED\n\t\t461 = ERR_NEEDMOREPARAMS\n\t\t462 = ERR_ALREADYREGISTRED\n\t\t463 = ERR_NOPERMFORHOST\n\t\t464 = ERR_PASSWDMISMATCH\n\t\t465 = ERR_YOUREBANNEDCREEP\n\t\t466 = ERR_YOUWILLBEBANNED\n\t\t467 = ERR_KEYSET\n\t\t471 = ERR_CHANNELISFULL\n\t\t472 = ERR_UNKNOWNMODE\n\t\t473 = ERR_INVITEONLYCHAN\n\t\t474 = ERR_BANNEDFROMCHAN\n\t\t475 = ERR_BADCHANNELKEY\n\t\t476 = ERR_BADCHANMASK\n\t\t477 = ERR_NOCHANMODES\n\t\t478 = ERR_BANLISTFULL\n\t\t481 = ERR_NOPRIVILEGES\n\t\t482 = ERR_CHANOPRIVSNEEDED\n\t\t483 = ERR_CANTKILLSERVER\n\t\t484 = ERR_RESTRICTED\n\t\t485 = ERR_UNIQOPPRIVSNEEDED\n\t\t491 = ERR_NOOPERHOST\n\t\t501 = ERR_UMODEUNKNOWNFLAG\n\t\t502 = ERR_USERSDONTMATCH\n\ninstance toInt IRCErrors where\n\ttoInt r = case r of\n\t\tERR_NOSUCHNICK = 401\n\t\tERR_NOSUCHSERVER = 402\n\t\tERR_NOSUCHCHANNEL = 403\n\t\tERR_CANNOTSENDTOCHAN = 404\n\t\tERR_TOOMANYCHANNELS = 405\n\t\tERR_WASNOSUCHNICK = 406\n\t\tERR_TOOMANYTARGETS = 407\n\t\tERR_NOSUCHSERVICE = 408\n\t\tERR_NOORIGIN = 409\n\t\tERR_NORECIPIENT = 411\n\t\tERR_NOTEXTTOSEND = 412\n\t\tERR_NOTOPLEVEL = 413\n\t\tERR_WILDTOPLEVEL = 414\n\t\tERR_BADMASK = 415\n\t\tERR_UNKNOWNCOMMAND = 421\n\t\tERR_NOMOTD = 422\n\t\tERR_NOADMININFO = 423\n\t\tERR_FILEERROR = 424\n\t\tERR_NONICKNAMEGIVEN = 431\n\t\tERR_ERRONEUSNICKNAME = 432\n\t\tERR_NICKNAMEINUSE = 433\n\t\tERR_NICKCOLLISION = 436\n\t\tERR_UNAVAILRESOURCE = 437\n\t\tERR_USERNOTINCHANNEL = 441\n\t\tERR_NOTONCHANNEL = 442\n\t\tERR_USERONCHANNEL = 443\n\t\tERR_NOLOGIN = 444\n\t\tERR_SUMMONDISABLED = 445\n\t\tERR_USERSDISABLED = 446\n\t\tERR_NOTREGISTERED = 451\n\t\tERR_NEEDMOREPARAMS = 461\n\t\tERR_ALREADYREGISTRED = 462\n\t\tERR_NOPERMFORHOST = 463\n\t\tERR_PASSWDMISMATCH = 464\n\t\tERR_YOUREBANNEDCREEP = 465\n\t\tERR_YOUWILLBEBANNED = 466\n\t\tERR_KEYSET = 467\n\t\tERR_CHANNELISFULL = 471\n\t\tERR_UNKNOWNMODE = 472\n\t\tERR_INVITEONLYCHAN = 473\n\t\tERR_BANNEDFROMCHAN = 474\n\t\tERR_BADCHANNELKEY = 475\n\t\tERR_BADCHANMASK = 476\n\t\tERR_NOCHANMODES = 477\n\t\tERR_BANLISTFULL = 478\n\t\tERR_NOPRIVILEGES = 481\n\t\tERR_CHANOPRIVSNEEDED = 482\n\t\tERR_CANTKILLSERVER = 483\n\t\tERR_RESTRICTED = 484\n\t\tERR_UNIQOPPRIVSNEEDED = 485\n\t\tERR_NOOPERHOST = 491\n\t\tERR_UMODEUNKNOWNFLAG = 501\n\t\tERR_USERSDONTMATCH = 502\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"d3b2be2ad1c50a47c8d0cee77d18f833267f0df3","subject":"Create example.dcl","message":"Create example.dcl","repos":"chuckwoodjohn\/py_console_a1.0","old_file":"examples\/example.dcl","new_file":"examples\/example.dcl","new_contents":"{\n\"example\":{\n\t\"hello_world\":\"hello_world\"\n\t}\n}\n","old_contents":"","returncode":1,"stderr":"error: pathspec 'examples\/example.dcl' did not match any file(s) known to git\n","license":"bsd-2-clause","lang":"Clean"} {"commit":"f0116814ce7ba06f1adb1e9ec13425759dbe2a21","subject":"Cleanup suggestion generation","message":"Cleanup suggestion generation\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Clean.Types\nimport Clean.Types.Parse\nimport Clean.Types.Unify\nimport Clean.Types.Util\nimport Control.Applicative\nimport Control.Monad => qualified join\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt, on, `on`\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Options\nimport System.Time\nfrom Text import class Text(concat,join,toLowerCase), instance Text String, <+\nimport Text.GenJSON\n\nimport Cloogle.API\nimport Cloogle.DB\nimport Cloogle.Search\n\nimport Util.SimpleTCPServer\nimport Util.Cache\nimport Util.Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\nCACHE_NS_THRESHOLD :== 20000000\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Maybe [String]\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (alwaysUnique,db) = alwaysUniquePredicate db\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True alwaysUnique allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.Request.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> unprepare <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\nwhere\n\tunprepare :: !Type -> Type\n\tunprepare (Type t ts) = Type t (map unprepare ts)\n\tunprepare (Func is t tc) = Func (map unprepare is) (unprepare t) (map unprepareTR tc)\n\tunprepare (Var tv) = Var (tv % (1,size tv-1))\n\tunprepare (Cons v ts) = Cons (v % (1,size v-1)) (map unprepare ts)\n\tunprepare (Uniq t) = Uniq (unprepare t)\n\tunprepare (Forall ts t tc) = Forall (map unprepare ts) (unprepare t) (map unprepareTR tc)\n\tunprepare (Arrow mt) = Arrow (unprepare <$> mt)\n\n\tunprepareTR :: !TypeRestriction -> TypeRestriction\n\tunprepareTR (Instance c ts) = Instance c (map unprepare ts)\n\tunprepareTR (Derivation g t) = Derivation g (unprepare t)\n\n:: Options =\n\t{ port :: !Int\n\t, reload_cache :: !Bool\n\t, test_file :: !Maybe FilePath\n\t, test_options :: ![TestOption]\n\t}\n\n:: TestOption = NoUnify\n\ninstance zero Options\nwhere\n\tzero =\n\t\t{ port = 31215\n\t\t, reload_cache = False\n\t\t, test_file = Nothing\n\t\t, test_options = []\n\t\t}\n\noptionDescription :: Option Options\noptionDescription = WithHelp True $ Options\n\t[ Shorthand \"-p\" \"--port\" $ Option\n\t\t\"--port\"\n\t\t(\\port opts -> case (toInt port, port) of\n\t\t\t(0, \"0\") -> Error [\"Cannot use port 0\"]\n\t\t\t(0, p) -> Error [\"'\" <+ p <+ \"' is not an integer\"]\n\t\t\t(p, _) -> Ok {Options | opts & port=p})\n\t\t\"PORT\"\n\t\t\"Listen on port PORT (default: 31215)\"\n\t, Flag\n\t\t\"--reload-cache\"\n\t\t(\\opts -> Ok {opts & reload_cache=True})\n\t\t\"Reload the cache in the background\"\n\t, Option\n\t\t\"--test\"\n\t\t(\\file opts -> Ok {opts & test_file=Just file})\n\t\t\"FILE\"\n\t\t\"Load queries from FILE and execute them (do not start a TCP server)\"\n\t, Flag\n\t\t\"--test-no-unify\"\n\t\t(\\opts -> Ok {opts & test_options=[NoUnify:opts.test_options]})\n\t\t\"Do not test queries that require unification (only used with --test)\"\n\t]\n\nStart w\n# ([prog:args], w) = getCommandLine w\n# opts = parseOptions optionDescription args zero\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< join \"\\n\" (fromError opts) <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n| isJust opts.test_file\n\t# (ok,f,w) = fopen (fromJust opts.test_file) FReadText w\n\t| not ok\n\t\t# (io,w) = stdio w\n\t\t# io = io <<< \"Could not open test file\\n\"\n\t\t# (_,w) = fclose io w\n\t\t= w\n\t= test opts.test_options f db w\n#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w)\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\nhandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\nhandle Nothing db w = (err InvalidInput \"Couldn't parse input\", (Nothing,0), db, w)\nhandle (Just request=:{unify,name,page}) db w\n\t#! (start,w) = nsTime w\n\t\/\/Check cache\n\t#! (key,db) = toRequestCacheKey db request\n\t#! (mbResponse, w) = readCache key w\n\t| isJust mbResponse\n\t\t# r = fromJust mbResponse\n\t\t= respond start Nothing {r & return = if (r.return == 0) 1 r.return} db w\n\t| isJust name && size (fromJust name) > 40\n\t\t= respond start Nothing (err InvalidName \"Function name too long\") db w\n\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t= respond start Nothing (err InvalidName \"Name cannot contain spaces\") db w\n\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t= respond start Nothing (err InvalidType \"Couldn't parse type\") db w\n\t| all isNothing [unify,name,request.typeName,request.className] && isNothing request.using\n\t\t= respond start Nothing (err InvalidInput \"Empty query\") db w\n\t\/\/ Results\n\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t#! (res,db) = search request db\n\t#! results = drop drop_n res\n\t#! more = max 0 (length results - MAX_RESULTS)\n\t\/\/ Suggestions\n\t#! reslen = length results\n\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\tJust t -> suggs name reslen t db\n\t\tNothing -> (Nothing, db)\n\t#! (db,w) = seqSt\n\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t(fromMaybe [] suggestions)\n\t\t(db,w)\n\t#! suggestions = sortBy ((<) `on` snd) <$> map (appSnd length) <$> suggestions\n\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\/\/ Response\n\t#! response = if (isEmpty results)\n\t\t(err NoResults \"No results\")\n\t\t{ zero\n\t\t& data = results\n\t\t, more_available = Just more\n\t\t, suggestions = suggestions\n\t\t}\n\t\/\/ Save page prefetches\n\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\/\/ Save cache file\n\t= respond start (Just key) response db w\nwhere\n\trespond :: !Timespec !(Maybe RequestCacheKey) !Response !*CloogleDB !*World ->\n\t\t*(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\trespond start key r db w\n\t#! (end,w) = nsTime w\n\t#! duration = 1000000000 * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec\n\t#! cache = duration > CACHE_NS_THRESHOLD\n\t= (r, (if cache (cacheKey <$> key) Nothing, duration \/ 1000), db, case (cache,key) of\n\t\t(True,Just k) -> writeCache LongTerm k r w\n\t\t_ -> w)\n\n\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\tcachePages key _ _ _ [] w = w\n\tcachePages key 0 _ _ _ w = w\n\tcachePages key npages i response results w\n\t# w = writeCache Brief req` resp` w\n\t= cachePages key (npages - 1) (i + 1) response keep w\n\twhere\n\t\treq` = { key & c_page = key.c_page + i }\n\t\tresp` =\n\t\t\t{ response\n\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t, data = give\n\t\t\t}\n\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Int !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n nresults t db\n\t# (swapped, db) = swap db\n\t# (capitalized, db) = capitalize db\n\t# suggestions = case swapped ++ capitalized of\n\t\t[] -> Nothing\n\t\tss -> Just ss\n\t= (suggestions, db)\n\twhere\n\t\tswap db = case t of\n\t\t\tFunc is r cc | length is < 3\n\t\t\t\t-> appFst (filter enough) $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\t\t\t\twith\n\t\t\t\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\t\t\t\\\\ is` <- permutations is | is` <> is]\n\t\t\t_ -> ([], db)\n\n\t\tcapitalize db = case t` of\n\t\t\tJust t` | t <> t` -> appFst (\\res -> [(req,res)]) $ search req db\n\t\t\t\twith req = {zero & name=n, unify=Just $ concat $ print False t`}\n\t\t\t_ -> ([], db)\n\t\twhere\n\t\t\tt` = assignAll\n\t\t\t\t[ (\"int\", Type \"Int\" [])\n\t\t\t\t, (\"bool\", Type \"Bool\" [])\n\t\t\t\t, (\"char\", Type \"Char\" [])\n\t\t\t\t, (\"real\", Type \"Real\" [])\n\t\t\t\t, (\"file\", Type \"File\" [])\n\t\t\t\t, (\"string\", Type \"String\" [])\n\t\t\t\t, (\"dynamic\", Type \"Dynamic\" [])\n\t\t\t\t, (\"world\", Uniq (Type \"World\" []))\n\t\t\t\t] t\n\n\t\tenough :: (Request, [Result]) -> Bool\n\t\tenough (_, res) = enough` nresults res\n\t\twhere\n\t\t\tenough` 0 _ = True\n\t\t\tenough` _ [] = False\n\t\t\tenough` n [_:xs] = enough` (n-1) xs\n\nreloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World)\nreloadCache (db,w)\n# (ks,w) = allCacheKeys LongTerm w\n= loop ks db w\nwhere\n\tloop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World)\n\tloop [] db w = (db,w)\n\tloop [k:ks] db w\n\t# w = removeFromCache LongTerm k w\n\t# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w\n\t# db = resetDB db\n\t= loop ks db w\n\ndoInBackground :: (*a -> *a) *a -> *a\ndoInBackground f w\n#! (pid,w) = fork w\n| pid < 0 = abort \"fork failed\\n\"\n| pid > 0 = w \/\/ Parent: return directly\n| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\ntest :: ![TestOption] !*File !*CloogleDB !*World -> *World\ntest opts queries db w\n# (e,queries) = fend queries\n| e = w\n# (qstring,queries) = freadline queries\n# qstring = {c \\\\ c <-: qstring | c <> '\\n' && c <> '\\r'}\n# q = parseSingleLineRequest qstring\n| isError q\n\t# w = snd $ fclose (stderr <<< \"Warning: could not parse '\" <<< qstring <<< \"'; \" <<< fromError q <<< \"\\n\") w\n\t= test opts queries db w\n# q = fromOk q\n| excluded opts q\n\t= test opts queries db w\n# (_,_,db,w) = handle (Just q) db w\n= test opts queries db w\nwhere\n\texcluded :: ![TestOption] !Request -> Bool\n\texcluded [] _ = False\n\texcluded [NoUnify:os] r = isJust r.unify || excluded os r\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: MicroSeconds :== Int\n\n:: LogMessage` :== LogMessage (Maybe Request) Response (Maybe CacheKey, MicroSeconds)\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, microseconds :: Int\n\t, request :: Maybe Request\n\t, cachekey :: Maybe String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response (ck,us)) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, microseconds = us\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Clean.Types\nimport Clean.Types.Parse\nimport Clean.Types.Unify\nimport Clean.Types.Util\nimport Control.Applicative\nimport Control.Monad => qualified join\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt, on, `on`\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Options\nimport System.Time\nfrom Text import class Text(concat,join,toLowerCase), instance Text String, <+\nimport Text.GenJSON\n\nimport Cloogle.API\nimport Cloogle.DB\nimport Cloogle.Search\n\nimport Util.SimpleTCPServer\nimport Util.Cache\nimport Util.Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\nCACHE_NS_THRESHOLD :== 20000000\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Maybe [String]\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (alwaysUnique,db) = alwaysUniquePredicate db\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True alwaysUnique allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.Request.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> unprepare <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\nwhere\n\tunprepare :: !Type -> Type\n\tunprepare (Type t ts) = Type t (map unprepare ts)\n\tunprepare (Func is t tc) = Func (map unprepare is) (unprepare t) (map unprepareTR tc)\n\tunprepare (Var tv) = Var (tv % (1,size tv-1))\n\tunprepare (Cons v ts) = Cons (v % (1,size v-1)) (map unprepare ts)\n\tunprepare (Uniq t) = Uniq (unprepare t)\n\tunprepare (Forall ts t tc) = Forall (map unprepare ts) (unprepare t) (map unprepareTR tc)\n\tunprepare (Arrow mt) = Arrow (unprepare <$> mt)\n\n\tunprepareTR :: !TypeRestriction -> TypeRestriction\n\tunprepareTR (Instance c ts) = Instance c (map unprepare ts)\n\tunprepareTR (Derivation g t) = Derivation g (unprepare t)\n\n:: Options =\n\t{ port :: !Int\n\t, reload_cache :: !Bool\n\t, test_file :: !Maybe FilePath\n\t, test_options :: ![TestOption]\n\t}\n\n:: TestOption = NoUnify\n\ninstance zero Options\nwhere\n\tzero =\n\t\t{ port = 31215\n\t\t, reload_cache = False\n\t\t, test_file = Nothing\n\t\t, test_options = []\n\t\t}\n\noptionDescription :: Option Options\noptionDescription = WithHelp True $ Options\n\t[ Shorthand \"-p\" \"--port\" $ Option\n\t\t\"--port\"\n\t\t(\\port opts -> case (toInt port, port) of\n\t\t\t(0, \"0\") -> Error [\"Cannot use port 0\"]\n\t\t\t(0, p) -> Error [\"'\" <+ p <+ \"' is not an integer\"]\n\t\t\t(p, _) -> Ok {Options | opts & port=p})\n\t\t\"PORT\"\n\t\t\"Listen on port PORT (default: 31215)\"\n\t, Flag\n\t\t\"--reload-cache\"\n\t\t(\\opts -> Ok {opts & reload_cache=True})\n\t\t\"Reload the cache in the background\"\n\t, Option\n\t\t\"--test\"\n\t\t(\\file opts -> Ok {opts & test_file=Just file})\n\t\t\"FILE\"\n\t\t\"Load queries from FILE and execute them (do not start a TCP server)\"\n\t, Flag\n\t\t\"--test-no-unify\"\n\t\t(\\opts -> Ok {opts & test_options=[NoUnify:opts.test_options]})\n\t\t\"Do not test queries that require unification (only used with --test)\"\n\t]\n\nStart w\n# ([prog:args], w) = getCommandLine w\n# opts = parseOptions optionDescription args zero\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< join \"\\n\" (fromError opts) <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n| isJust opts.test_file\n\t# (ok,f,w) = fopen (fromJust opts.test_file) FReadText w\n\t| not ok\n\t\t# (io,w) = stdio w\n\t\t# io = io <<< \"Could not open test file\\n\"\n\t\t# (_,w) = fclose io w\n\t\t= w\n\t= test opts.test_options f db w\n#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w)\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\nhandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\nhandle Nothing db w = (err InvalidInput \"Couldn't parse input\", (Nothing,0), db, w)\nhandle (Just request=:{unify,name,page}) db w\n\t#! (start,w) = nsTime w\n\t\/\/Check cache\n\t#! (key,db) = toRequestCacheKey db request\n\t#! (mbResponse, w) = readCache key w\n\t| isJust mbResponse\n\t\t# r = fromJust mbResponse\n\t\t= respond start Nothing {r & return = if (r.return == 0) 1 r.return} db w\n\t| isJust name && size (fromJust name) > 40\n\t\t= respond start Nothing (err InvalidName \"Function name too long\") db w\n\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t= respond start Nothing (err InvalidName \"Name cannot contain spaces\") db w\n\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t= respond start Nothing (err InvalidType \"Couldn't parse type\") db w\n\t| all isNothing [unify,name,request.typeName,request.className] && isNothing request.using\n\t\t= respond start Nothing (err InvalidInput \"Empty query\") db w\n\t\/\/ Results\n\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t#! (res,db) = search request db\n\t#! results = drop drop_n res\n\t#! more = max 0 (length results - MAX_RESULTS)\n\t\/\/ Suggestions\n\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\tJust t -> suggs name t db\n\t\tNothing -> (Nothing, db)\n\t#! (db,w) = seqSt\n\t\t(\\(_,req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t(fromMaybe [] suggestions)\n\t\t(db,w)\n\t#! suggestions\n\t\t= sortBy ((<) `on` snd) <$>\n\t\t\tmap (\\(_,req,reslen) -> (req,reslen)) <$>\n\t\t\tfilter (\\(always,_,sugres) -> always || sugres >= reslen) <$>\n\t\t\tmap (appThd3 length) <$> suggestions\n\t\twith reslen = length results\n\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\/\/ Response\n\t#! response = if (isEmpty results)\n\t\t(err NoResults \"No results\")\n\t\t{ zero\n\t\t& data = results\n\t\t, more_available = Just more\n\t\t, suggestions = suggestions\n\t\t}\n\t\/\/ Save page prefetches\n\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\/\/ Save cache file\n\t= respond start (Just key) response db w\nwhere\n\trespond :: !Timespec !(Maybe RequestCacheKey) !Response !*CloogleDB !*World ->\n\t\t*(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\trespond start key r db w\n\t#! (end,w) = nsTime w\n\t#! duration = 1000000000 * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec\n\t#! cache = duration > CACHE_NS_THRESHOLD\n\t= (r, (if cache (cacheKey <$> key) Nothing, duration \/ 1000), db, case (cache,key) of\n\t\t(True,Just k) -> writeCache LongTerm k r w\n\t\t_ -> w)\n\n\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\tcachePages key _ _ _ [] w = w\n\tcachePages key 0 _ _ _ w = w\n\tcachePages key npages i response results w\n\t# w = writeCache Brief req` resp` w\n\t= cachePages key (npages - 1) (i + 1) response keep w\n\twhere\n\t\treq` = { key & c_page = key.c_page + i }\n\t\tresp` =\n\t\t\t{ response\n\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t, data = give\n\t\t\t}\n\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Bool, Request, [Result])], *CloogleDB)\n\tsuggs n t db\n\t# (swapped, db) = swap db\n\t# (capitalized, db) = capitalize db\n\t# suggestions = case fromMaybe [] swapped ++ [c \\\\ Just c <- [capitalized]] of\n\t\t[] -> Nothing\n\t\tss -> Just ss\n\t= (suggestions, db)\n\twhere\n\t\tswap db = case t of\n\t\t\tFunc is r cc | length is < 3\n\t\t\t\t-> appFst Just $ mapSt (\\r -> appFst (tuple3 False r) o search r o resetDB) reqs db\n\t\t\t\twith\n\t\t\t\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\t\t\t\\\\ is` <- permutations is | is` <> is]\n\t\t\t_ -> (Nothing, db)\n\n\t\tcapitalize db = case t` of\n\t\t\tJust t` | t <> t` -> appFst (Just o tuple3 True req) $ search req db\n\t\t\t\twith req = {zero & name=n, unify=Just $ concat $ print False t`}\n\t\t\t_ -> (Nothing, db)\n\t\twhere\n\t\t\tt` = assignAll\n\t\t\t\t[ (\"int\", Type \"Int\" [])\n\t\t\t\t, (\"bool\", Type \"Bool\" [])\n\t\t\t\t, (\"char\", Type \"Char\" [])\n\t\t\t\t, (\"real\", Type \"Real\" [])\n\t\t\t\t, (\"file\", Type \"File\" [])\n\t\t\t\t, (\"string\", Type \"String\" [])\n\t\t\t\t, (\"dynamic\", Type \"Dynamic\" [])\n\t\t\t\t, (\"world\", Uniq (Type \"World\" []))\n\t\t\t\t] t\n\nreloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World)\nreloadCache (db,w)\n# (ks,w) = allCacheKeys LongTerm w\n= loop ks db w\nwhere\n\tloop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World)\n\tloop [] db w = (db,w)\n\tloop [k:ks] db w\n\t# w = removeFromCache LongTerm k w\n\t# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w\n\t# db = resetDB db\n\t= loop ks db w\n\ndoInBackground :: (*a -> *a) *a -> *a\ndoInBackground f w\n#! (pid,w) = fork w\n| pid < 0 = abort \"fork failed\\n\"\n| pid > 0 = w \/\/ Parent: return directly\n| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\ntest :: ![TestOption] !*File !*CloogleDB !*World -> *World\ntest opts queries db w\n# (e,queries) = fend queries\n| e = w\n# (qstring,queries) = freadline queries\n# qstring = {c \\\\ c <-: qstring | c <> '\\n' && c <> '\\r'}\n# q = parseSingleLineRequest qstring\n| isError q\n\t# w = snd $ fclose (stderr <<< \"Warning: could not parse '\" <<< qstring <<< \"'; \" <<< fromError q <<< \"\\n\") w\n\t= test opts queries db w\n# q = fromOk q\n| excluded opts q\n\t= test opts queries db w\n# (_,_,db,w) = handle (Just q) db w\n= test opts queries db w\nwhere\n\texcluded :: ![TestOption] !Request -> Bool\n\texcluded [] _ = False\n\texcluded [NoUnify:os] r = isJust r.unify || excluded os r\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: MicroSeconds :== Int\n\n:: LogMessage` :== LogMessage (Maybe Request) Response (Maybe CacheKey, MicroSeconds)\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, microseconds :: Int\n\t, request :: Maybe Request\n\t, cachekey :: Maybe String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response (ck,us)) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, microseconds = us\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"cd75fc36319812f7f36d29719596950abdb3895a","subject":"Use NOTICE instead of PRIVMSG","message":"Use NOTICE instead of PRIVMSG\n","repos":"clean-cloogle\/clean-irc","old_file":"cloogleirc.icl","new_file":"cloogleirc.icl","new_contents":"module cloogleirc\n\nimport Cloogle\nimport GenPrint\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nimport Data.Either\nfrom Data.Func import $, mapSt\nfrom Text import class Text(..), instance Text String, instance + String\n\nimport Internet.HTTP\n\nimport Text.JSON\n\nimport Text.URI\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad, instance Monad Maybe, >>=\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport System.CommandLine\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\nimport IRC\nimport IRCBot\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# s = if (startsWith \"http:\/\/\" s) s (if (startsWith \"https:\/\/\" s) s (\"http:\/\/\" + s))\n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doHTTPRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} 10000 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\ncloogle :: String *World -> (String, *World)\ncloogle data w\n# (mer, w) = doHTTPRequestL\n\t\t{ newHTTPRequest\n\t\t& req_path = \"\/api.php\"\n\t\t, req_query = \"?str=\" + urlEncode data\n\t\t, req_headers = 'DM'.fromList [(\"User-Agent\", \"cloogle-irc\")]\n\t\t, server_name = \"cloogle.org\"\n\t\t, server_port = 80} 10000 10 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= case fromJSON $ fromString resp.HTTPResponse.rsp_data of\n\tNothing = (\"couldn't parse json\", w)\n\tJust clr = (\"Results for \" + data + \" -- https:\/\/cloogle.org\/#\" +\n\t\treplaceSubString \"+\" \"%20\" (urlEncode data) + \"\\n\" +\n\t\tprocessResults clr, w)\n\twhere\n\t\tprocessResults :: Response -> String\n\t\tprocessResults resp\n\t\t| resp.return > 127 = \"Failed: return code: \" + toString resp.return + \", \" + resp.msg\n\t\t= join \"\\n\" $ map processResult $ take 3 resp.data\n\t\t\n\t\tprocessResult :: Result -> String\n\t\tprocessResult (FunctionResult (br, {func}))\n\t\t\t= \"Function in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ func\n\t\tprocessResult (TypeResult (br, {type}))\n\t\t\t= \"Type in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ limitResults type\n\t\tprocessResult (ClassResult (br, {class_name,class_funs}))\n\t\t\t= \"Class in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ class_name +++ \" with \"\n\t\t\t\t+++ toString (length class_funs) +++ \" class functions\"\n\t\tprocessResult (ModuleResult (br, _))\n\t\t\t= \"Module in \" +++ br.library +++ \": \" +++ br.modul\n\n\t\tlimitResults :: String -> String\n\t\tlimitResults s\n\t\t# lines = split \"\\n\" s\n\t\t| length lines > 4 = limitResults (join \"\\n\" (take 3 lines) + \"\\n...\")\n\t\t= join \"\\n\" (map maxWidth lines)\n\t\t\n\t\tmaxWidth :: String -> String\n\t\tmaxWidth s\n\t\t| size s > 80 = subString 0 77 s + \"...\"\n\t\t= s\n\n:: BotSettings =\n\t\t{ bs_nick :: String\n\t\t, bs_nickserv :: Maybe String\n\t\t, bs_autojoin :: [String]\n\t\t, bs_port :: Int\n\t\t, bs_server :: String\n\t\t}\n\nStart :: *World -> (MaybeErrorString (), *World)\nStart w\n# ([arg0:args], w) = getCommandLine w\n# bs = parseCLI args \n| isError bs = (Error $ \"\\n\" +++ fromError bs +++ \"\\n\", w)\n# (Ok bs) = bs\n= bot (bs.bs_server, bs.bs_port) (startup bs) shutdown () process w\n\twhere\n\t\tparseCLI :: [String] -> MaybeErrorString BotSettings\n\t\tparseCLI [] = Ok\n\t\t\t{ bs_nick = \"clooglebot\"\n\t\t\t, bs_nickserv = Nothing\n\t\t\t, bs_autojoin = []\n\t\t\t, bs_port = 6667\n\t\t\t, bs_server = \"irc.freenode.net\"\n\t\t\t}\n\t\tparseCLI [a:as]\n\t\t| a == \"-n\" || a == \"--nick\"\n\t\t\t= arg1 \"--nick\" as \\a c->{c & bs_nick=a}\n\t\t| a == \"-ns\" || a == \"--nickserv\"\n\t\t\t= arg1 \"--nickserv\" as \\a c->{c & bs_nickserv=Just a}\n\t\t| a == \"-a\" || a == \"--autojoin\"\n\t\t\t= arg1 \"--autojoin\" as \\a c->{c & bs_autojoin=c.bs_autojoin ++ [a]}\n\t\t| a == \"-p\" || a == \"--port\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_port=toInt a}\n\t\t| a == \"-s\" || a == \"--server\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_server=a}\n\t\t| a == \"-h\" || a == \"--help\" = Error $ join \"\\n\" $\n\t\t\t[ \"Usage: cloogle [OPTS]\"\n\t\t\t, \"Options:\"\n\t\t\t, \"\\t--nick\/-n NICKNAME Use the given nickname instead of clooglebot\"\n\t\t\t, \"\\t--nickserv\/-ns PW Identify via the given password with NickServ\"\n\t\t\t, \"\\t--port\/-p PORT Use the given port instead of port 6667\"\n\t\t\t, \"\\t--server\/-s SERVER Use the given server instead of irc.freenode.net\"\n\t\t\t, \"\\t--autojoin\/-a CHANNEL Add CHANNEL to the autojoin list. This command \"\n\t\t\t, \"\\t can be called multiple times. Beware that #\"\n\t\t\t, \"\\t has to be escaped in most shells\"\n\t\t\t]\n\t\t= Error $ \"Unknown option: \" +++ a\n\n\t\targ1 name [] _ = Error $ name +++ \" requires an argument\"\n\t\targ1 name [a:as] f = parseCLI as >>= Ok o f a\n\n\t\tnickserv pw = PRIVMSG (CSepList [\"NickServ\"]) $ \"IDENTIFY \" +++ pw\n\n\t\ttoPrefix c = {irc_prefix=Nothing,irc_command=Right c}\n\n\t\tstartup bs = map toPrefix $\n\t\t\t[ NICK bs.bs_nick Nothing\n\t\t\t, USER \"cloogle\" \"cloogle\" \"cloogle\" \"Cloogle bot\"\n\t\t\t]++ maybe [] (pure o nickserv) bs.bs_nickserv\n\t\t\t ++ if (isEmpty bs.bs_autojoin) []\n\t\t\t\t[JOIN (CSepList bs.bs_autojoin) Nothing]\n\t\tshutdown = map toPrefix [QUIT $ Just \"Bye\"]\n\n\t\tprocess :: IRCMessage () *World -> (Maybe [IRCMessage], (), *World)\n\t\tprocess im s w = case im.irc_command of\n\t\t\tLeft numr = (Just [], (), w)\n\t\t\tRight cmd = case process` im.irc_prefix cmd w of\n\t\t\t\t(Nothing, w) = (Nothing, (), w)\n\t\t\t\t(Just cs, w) = (Just $ map toPrefix cs, (), w)\n\n\t\tprocess` :: (Maybe (Either IRCUser String)) IRCCommand *World -> (Maybe [IRCCommand], *World)\n\t\tprocess` (Just (Left user)) (PRIVMSG t m) w\n\t\t\t| m == \"!restart\" = (Nothing, w)\n\t\t\t| m.[0] == '!'\n\t\t\t\t# (msgs, w) = realProcess (split \" \" $ m % (1, size m)) w\n\t\t\t\t= (Just $ map (NOTICE recipient) msgs, w)\n\t\t\t= (Just [], w)\n\t\twhere\n\t\t\trecipient = case (\\(CSepList [t:_]) -> t.[0]) t of\n\t\t\t\t'#' -> t\n\t\t\t\t_ -> CSepList [user.irc_nick]\n\t\tprocess` _ (PING t mt) w = (Just [PONG t mt], w)\n\t\tprocess` _ _ w = (Just [], w)\n\n\t\trealProcess :: [String] *World -> ([String], *World)\n\t\trealProcess [\"help\",x:xs] w = ((case x of\n\t\t\t\"help\" =\n\t\t\t\t[ \"Usage: !help [ARG]\"\n\t\t\t\t, \"Show this help, or the specific help of the argument\"]\n\t\t\t\"ping\" =\n\t\t\t\t[ \"Usage: !ping [ARG [ARG ...]]\"\n\t\t\t\t, \"Ping the bot, it will pong the arguments back\"]\n\t\t\t\"shorten\" =\n\t\t\t\t[ \"Usage: !shorten URL [URL [URL ...]]\"\n\t\t\t\t, \"Shorten the given urls with the cloo.gl url shortener\"]\n\t\t\t\"query\" =\n\t\t\t\t[ \"Usage: !query QUERY\"\n\t\t\t\t, \"Query QUERY in cloogle and return the results\"]\n\t\t\t\"restart\" =\n\t\t\t\t[ \"Usage: !restart\"\n\t\t\t\t, \"Restart the bot\"]\n\t\t\tx = [\"Unknown command: \" +++ x]\n\t\t\t), w)\n\t\trealProcess [\"help\"] w = (\n\t\t\t[\"Type !help cmd for command specific help\"\n\t\t\t,\"available commands: help, ping, shorten, query, restart\"], w)\n\t\trealProcess [\"ping\":xs] w = ([\"pong \" +++ join \" \" xs], w)\n\t\trealProcess [\"shorten\":xs] w = case xs of\n\t\t\t[] = ([\"shorten requires at least one argument\"], w)\n\t\t\txs = mapSt shorten xs w\n\t\trealProcess [\"query\":xs] w = case xs of\n\t\t\t[] = ([\"query requires one or more arguments\"], w)\n\t\t\txs = appFst (split \"\\n\") $ cloogle (join \" \" xs) w\n\t\trealProcess [\"restart\":_] w = ([\"restart takes no arguments\"], w)\n\t\trealProcess [c:_] w = ([join \" \" [\n\t\t\t\"Unknown cmd: \", c, \", type !help to get help\"]], w)\n","old_contents":"module cloogleirc\n\nimport Cloogle\nimport GenPrint\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nimport Data.Either\nfrom Data.Func import $, mapSt\nfrom Text import class Text(..), instance Text String, instance + String\n\nimport Internet.HTTP\n\nimport Text.JSON\n\nimport Text.URI\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad, instance Monad Maybe, >>=\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport System.CommandLine\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\nimport IRC\nimport IRCBot\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# s = if (startsWith \"http:\/\/\" s) s (if (startsWith \"https:\/\/\" s) s (\"http:\/\/\" + s))\n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doHTTPRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} 10000 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\ncloogle :: String *World -> (String, *World)\ncloogle data w\n# (mer, w) = doHTTPRequestL\n\t\t{ newHTTPRequest\n\t\t& req_path = \"\/api.php\"\n\t\t, req_query = \"?str=\" + urlEncode data\n\t\t, req_headers = 'DM'.fromList [(\"User-Agent\", \"cloogle-irc\")]\n\t\t, server_name = \"cloogle.org\"\n\t\t, server_port = 80} 10000 10 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= case fromJSON $ fromString resp.HTTPResponse.rsp_data of\n\tNothing = (\"couldn't parse json\", w)\n\tJust clr = (\"Results for \" + data + \" -- https:\/\/cloogle.org\/#\" +\n\t\treplaceSubString \"+\" \"%20\" (urlEncode data) + \"\\n\" +\n\t\tprocessResults clr, w)\n\twhere\n\t\tprocessResults :: Response -> String\n\t\tprocessResults resp\n\t\t| resp.return > 127 = \"Failed: return code: \" + toString resp.return + \", \" + resp.msg\n\t\t= join \"\\n\" $ map processResult $ take 3 resp.data\n\t\t\n\t\tprocessResult :: Result -> String\n\t\tprocessResult (FunctionResult (br, {func}))\n\t\t\t= \"Function in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ func\n\t\tprocessResult (TypeResult (br, {type}))\n\t\t\t= \"Type in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ limitResults type\n\t\tprocessResult (ClassResult (br, {class_name,class_funs}))\n\t\t\t= \"Class in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ class_name +++ \" with \"\n\t\t\t\t+++ toString (length class_funs) +++ \" class functions\"\n\t\tprocessResult (ModuleResult (br, _))\n\t\t\t= \"Module in \" +++ br.library +++ \": \" +++ br.modul\n\n\t\tlimitResults :: String -> String\n\t\tlimitResults s\n\t\t# lines = split \"\\n\" s\n\t\t| length lines > 4 = limitResults (join \"\\n\" (take 3 lines) + \"\\n...\")\n\t\t= join \"\\n\" (map maxWidth lines)\n\t\t\n\t\tmaxWidth :: String -> String\n\t\tmaxWidth s\n\t\t| size s > 80 = subString 0 77 s + \"...\"\n\t\t= s\n\n:: BotSettings =\n\t\t{ bs_nick :: String\n\t\t, bs_nickserv :: Maybe String\n\t\t, bs_autojoin :: [String]\n\t\t, bs_port :: Int\n\t\t, bs_server :: String\n\t\t}\n\nStart :: *World -> (MaybeErrorString (), *World)\nStart w\n# ([arg0:args], w) = getCommandLine w\n# bs = parseCLI args \n| isError bs = (Error $ \"\\n\" +++ fromError bs +++ \"\\n\", w)\n# (Ok bs) = bs\n= bot (bs.bs_server, bs.bs_port) (startup bs) shutdown () process w\n\twhere\n\t\tparseCLI :: [String] -> MaybeErrorString BotSettings\n\t\tparseCLI [] = Ok\n\t\t\t{ bs_nick = \"clooglebot\"\n\t\t\t, bs_nickserv = Nothing\n\t\t\t, bs_autojoin = []\n\t\t\t, bs_port = 6667\n\t\t\t, bs_server = \"irc.freenode.net\"\n\t\t\t}\n\t\tparseCLI [a:as]\n\t\t| a == \"-n\" || a == \"--nick\"\n\t\t\t= arg1 \"--nick\" as \\a c->{c & bs_nick=a}\n\t\t| a == \"-ns\" || a == \"--nickserv\"\n\t\t\t= arg1 \"--nickserv\" as \\a c->{c & bs_nickserv=Just a}\n\t\t| a == \"-a\" || a == \"--autojoin\"\n\t\t\t= arg1 \"--autojoin\" as \\a c->{c & bs_autojoin=c.bs_autojoin ++ [a]}\n\t\t| a == \"-p\" || a == \"--port\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_port=toInt a}\n\t\t| a == \"-s\" || a == \"--server\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_server=a}\n\t\t| a == \"-h\" || a == \"--help\" = Error $ join \"\\n\" $\n\t\t\t[ \"Usage: cloogle [OPTS]\"\n\t\t\t, \"Options:\"\n\t\t\t, \"\\t--nick\/-n NICKNAME Use the given nickname instead of clooglebot\"\n\t\t\t, \"\\t--nickserv\/-ns PW Identify via the given password with NickServ\"\n\t\t\t, \"\\t--port\/-p PORT Use the given port instead of port 6667\"\n\t\t\t, \"\\t--server\/-s SERVER Use the given server instead of irc.freenode.net\"\n\t\t\t, \"\\t--autojoin\/-a CHANNEL Add CHANNEL to the autojoin list. This command \"\n\t\t\t, \"\\t can be called multiple times. Beware that #\"\n\t\t\t, \"\\t has to be escaped in most shells\"\n\t\t\t]\n\t\t= Error $ \"Unknown option: \" +++ a\n\n\t\targ1 name [] _ = Error $ name +++ \" requires an argument\"\n\t\targ1 name [a:as] f = parseCLI as >>= Ok o f a\n\n\t\tnickserv pw = PRIVMSG (CSepList [\"NickServ\"]) $ \"IDENTIFY \" +++ pw\n\n\t\ttoPrefix c = {irc_prefix=Nothing,irc_command=Right c}\n\n\t\tstartup bs = map toPrefix $\n\t\t\t[ NICK bs.bs_nick Nothing\n\t\t\t, USER \"cloogle\" \"cloogle\" \"cloogle\" \"Cloogle bot\"\n\t\t\t]++ maybe [] (pure o nickserv) bs.bs_nickserv\n\t\t\t ++ if (isEmpty bs.bs_autojoin) []\n\t\t\t\t[JOIN (CSepList bs.bs_autojoin) Nothing]\n\t\tshutdown = map toPrefix [QUIT $ Just \"Bye\"]\n\n\t\tprocess :: IRCMessage () *World -> (Maybe [IRCMessage], (), *World)\n\t\tprocess im s w = case im.irc_command of\n\t\t\tLeft numr = (Just [], (), w)\n\t\t\tRight cmd = case process` im.irc_prefix cmd w of\n\t\t\t\t(Nothing, w) = (Nothing, (), w)\n\t\t\t\t(Just cs, w) = (Just $ map toPrefix cs, (), w)\n\n\t\tprocess` :: (Maybe (Either IRCUser String)) IRCCommand *World -> (Maybe [IRCCommand], *World)\n\t\tprocess` (Just (Left user)) (PRIVMSG t m) w\n\t\t\t| m == \"!restart\" = (Nothing, w)\n\t\t\t| m.[0] == '!'\n\t\t\t\t# (msgs, w) = realProcess (split \" \" $ m % (1, size m)) w\n\t\t\t\t= (Just $ map (PRIVMSG recipient) msgs, w)\n\t\t\t= (Just [], w)\n\t\twhere\n\t\t\trecipient = case (\\(CSepList [t:_]) -> t.[0]) t of\n\t\t\t\t'#' -> t\n\t\t\t\t_ -> CSepList [user.irc_nick]\n\t\tprocess` _ (PING t mt) w = (Just [PONG t mt], w)\n\t\tprocess` _ _ w = (Just [], w)\n\n\t\trealProcess :: [String] *World -> ([String], *World)\n\t\trealProcess [\"help\",x:xs] w = ((case x of\n\t\t\t\"help\" =\n\t\t\t\t[ \"Usage: !help [ARG]\"\n\t\t\t\t, \"Show this help, or the specific help of the argument\"]\n\t\t\t\"ping\" =\n\t\t\t\t[ \"Usage: !ping [ARG [ARG ...]]\"\n\t\t\t\t, \"Ping the bot, it will pong the arguments back\"]\n\t\t\t\"shorten\" =\n\t\t\t\t[ \"Usage: !shorten URL [URL [URL ...]]\"\n\t\t\t\t, \"Shorten the given urls with the cloo.gl url shortener\"]\n\t\t\t\"query\" =\n\t\t\t\t[ \"Usage: !query QUERY\"\n\t\t\t\t, \"Query QUERY in cloogle and return the results\"]\n\t\t\t\"restart\" =\n\t\t\t\t[ \"Usage: !restart\"\n\t\t\t\t, \"Restart the bot\"]\n\t\t\tx = [\"Unknown command: \" +++ x]\n\t\t\t), w)\n\t\trealProcess [\"help\"] w = (\n\t\t\t[\"Type !help cmd for command specific help\"\n\t\t\t,\"available commands: help, ping, shorten, query, restart\"], w)\n\t\trealProcess [\"ping\":xs] w = ([\"pong \" +++ join \" \" xs], w)\n\t\trealProcess [\"shorten\":xs] w = case xs of\n\t\t\t[] = ([\"shorten requires at least one argument\"], w)\n\t\t\txs = mapSt shorten xs w\n\t\trealProcess [\"query\":xs] w = case xs of\n\t\t\t[] = ([\"query requires one or more arguments\"], w)\n\t\t\txs = appFst (split \"\\n\") $ cloogle (join \" \" xs) w\n\t\trealProcess [\"restart\":_] w = ([\"restart takes no arguments\"], w)\n\t\trealProcess [c:_] w = ([join \" \" [\n\t\t\t\"Unknown cmd: \", c, \", type !help to get help\"]], w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"098419c33037e3fc55190ce47f1b411547f9e276","subject":"Restore cache reloading","message":"Restore cache reloading\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat,toLowerCase), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Bool\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = fromMaybe False r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = Just k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w)\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, CacheKey, !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", \"\", db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond key {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond key (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond key (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond key (err InvalidType \"Couldn't parse type\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond key response db w\n\twhere\n\t\trespond :: !RequestCacheKey !Response !*CloogleDB !*World -> *(!Response, !CacheKey, !*CloogleDB, !*World)\n\t\trespond key r db w = (r, cacheKey key, db, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World)\n\treloadCache (db,w)\n\t# (ks,w) = allCacheKeys LongTerm w\n\t= loop ks db w\n\twhere\n\t\tloop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World)\n\t\tloop [] db w = (db,w)\n\t\tloop [k:ks] db w\n\t\t# w = removeFromCache LongTerm k w\n\t\t# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w\n\t\t# db = resetDB db\n\t\t= loop ks db w\n\n\tdoInBackground :: (*a -> *a) *a -> *a\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat,toLowerCase), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Bool\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = fromMaybe False r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = Just k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n\/\/#! w = if opts.reload_cache (doInBackground (reloadCache db)) id w\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, CacheKey, !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", \"\", db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond key {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond key (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond key (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond key (err InvalidType \"Couldn't parse type\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond key response db w\n\twhere\n\t\trespond :: !RequestCacheKey !Response !*CloogleDB !*World -> *(!Response, !CacheKey, !*CloogleDB, !*World)\n\t\trespond key r db w = (r, cacheKey key, db, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !CloogleDB -> *World -> *World\n\treloadCache db = uncurry (flip (foldl (flip search))) o allCacheKeys LongTerm\n\twhere\n\t\tsearch :: !RequestCacheKey -> *World -> *World\n\t\tsearch r = thd3 o handle db (Just $ fromRequestCacheKey r) o removeFromCache LongTerm r\n\n\tdoInBackground :: (*World -> *World) *World -> *World\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"887494b894c78901d9f8dcf5d7484986ecf3dd2a","subject":"Remove unused code","message":"Remove unused code\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/Cloogle.dcl","new_file":"backend\/Cloogle.dcl","new_contents":"definition module Cloogle\n\nfrom StdOverloaded import class zero, class fromString, class toString, class <\n\nfrom Data.Maybe import :: Maybe\nfrom Text.JSON import generic JSONEncode, generic JSONDecode, :: JSONNode\n\n:: Request\n\t= { unify :: Maybe String\n\t , name :: Maybe String\n\t , className :: Maybe String\n\t , typeName :: Maybe String\n\t , modules :: Maybe [String]\n\t , libraries :: Maybe [String]\n\t , include_builtins :: Maybe Bool\n\t , include_core :: Maybe Bool\n\t , page :: Maybe Int\n\t }\n\n:: Response\n\t= { return :: Int\n\t , data :: [Result]\n\t , msg :: String\n\t , more_available :: Maybe Int\n\t , suggestions :: Maybe [(Request, Int)]\n\t }\n\n:: Result\n\t= FunctionResult FunctionResult\n\t| TypeResult TypeResult\n\t| ClassResult ClassResult\n\t| MacroResult MacroResult\n\t| ModuleResult ModuleResult\n\n:: BasicResult\n\t= { library :: String\n\t , filename :: String\n\t , modul :: String\n\t , dcl_line :: Maybe Int\n\t , icl_line :: Maybe Int\n\t , distance :: Int\n\t , builtin :: Maybe Bool\n\t }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras\n\t= { func :: String\n\t , unifier :: Maybe StrUnifier\n\t , cls :: Maybe ShortClassResult\n\t , constructor_of :: Maybe String\n\t , recordfield_of :: Maybe String\n\t , generic_derivations :: Maybe [(String, [LocationResult])]\n\t }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras\n\t= { type :: String\n\t , type_instances :: [(String, [String], [LocationResult])]\n\t , type_derivations :: [(String, [LocationResult])]\n\t }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras\n\t= { class_name :: String\n\t , class_heading :: String\n\t , class_funs :: [String]\n\t , class_instances :: [([String], [LocationResult])]\n\t }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras\n\t= { macro_name :: String\n\t , macro_representation :: String\n\t }\n\n:: ModuleResult :== (BasicResult, ModuleResultExtras)\n:: ModuleResultExtras\n\t= { module_is_core :: Bool\n\t }\n\n:: LocationResult :== (String, String, Maybe Int, Maybe Int)\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras,\n\tMacroResultExtras, ModuleResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras,\n\tMacroResultExtras, ModuleResultExtras\n\ninstance zero Request\ninstance zero Response\n\ninstance toString Request\ninstance toString Response\n\ninstance fromString (Maybe Request)\n\ninstance < BasicResult\ninstance < Result\n\nCLOOGLE_E_NORESULTS :== 127\nCLOOGLE_E_INVALIDINPUT :== 128\nCLOOGLE_E_INVALIDNAME :== 129\nCLOOGLE_E_INVALIDTYPE :== 130\n\nerr :: Int String -> Response\n","old_contents":"definition module Cloogle\n\nfrom StdOverloaded import class zero, class fromString, class toString, class <\n\nfrom Data.Maybe import :: Maybe\nfrom Text.JSON import generic JSONEncode, generic JSONDecode, :: JSONNode\n\n:: Request\n\t= { unify :: Maybe String\n\t , name :: Maybe String\n\t , className :: Maybe String\n\t , typeName :: Maybe String\n\t , modules :: Maybe [String]\n\t , libraries :: Maybe [String]\n\t , include_builtins :: Maybe Bool\n\t , include_core :: Maybe Bool\n\t , page :: Maybe Int\n\t }\n\n:: Response\n\t= { return :: Int\n\t , data :: [Result]\n\t , msg :: String\n\t , more_available :: Maybe Int\n\t , suggestions :: Maybe [(Request, Int)]\n\t }\n\n:: Result\n\t= FunctionResult FunctionResult\n\t| TypeResult TypeResult\n\t| ClassResult ClassResult\n\t| MacroResult MacroResult\n\t| ModuleResult ModuleResult\n\n:: BasicResult\n\t= { library :: String\n\t , filename :: String\n\t , modul :: String\n\t , dcl_line :: Maybe Int\n\t , icl_line :: Maybe Int\n\t , distance :: Int\n\t , builtin :: Maybe Bool\n\t }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras\n\t= { func :: String\n\t , unifier :: Maybe StrUnifier\n\t , cls :: Maybe ShortClassResult\n\t , constructor_of :: Maybe String\n\t , recordfield_of :: Maybe String\n\t , generic_derivations :: Maybe [(String, [LocationResult])]\n\t }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras\n\t= { type :: String\n\t , type_instances :: [(String, [String], [LocationResult])]\n\t , type_derivations :: [(String, [LocationResult])]\n\t }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras\n\t= { class_name :: String\n\t , class_heading :: String\n\t , class_funs :: [String]\n\t , class_instances :: [([String], [LocationResult])]\n\t }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras\n\t= { macro_name :: String\n\t , macro_representation :: String\n\t }\n\n:: ModuleResult :== (BasicResult, ModuleResultExtras)\n:: ModuleResultExtras\n\t= { module_is_core :: Bool\n\t }\n\n:: LocationResult :== (String, String, Maybe Int, Maybe Int)\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = MaybeError Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras,\n\tMacroResultExtras, ModuleResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras,\n\tMacroResultExtras, ModuleResultExtras\n\ninstance zero Request\ninstance zero Response\n\ninstance toString Request\ninstance toString Response\n\ninstance fromString (Maybe Request)\n\ninstance < BasicResult\ninstance < Result\n\nCLOOGLE_E_NORESULTS :== 127\nCLOOGLE_E_INVALIDINPUT :== 128\nCLOOGLE_E_INVALIDNAME :== 129\nCLOOGLE_E_INVALIDTYPE :== 130\n\nerr :: Int String -> Response\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"c664003e0f25a3c7c1fca664a9e7f2be8b0d0c55","subject":"Fix queries like :: Footballer to return the type definition as well","message":"Fix queries like :: Footballer to return the type definition as well\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nimport StdList\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\nfrom StdFunc import const, flip, id, o, seq\nfrom StdMisc import abort, undef\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable, instance Foldable Maybe\nfrom Data.Func import $\nimport Data.Functor\nimport Data.List\nimport Data.Maybe\nimport Data.Tuple\nimport System.CommandLine\nfrom Text import class Text(concat,trim,indexOf,toLowerCase,split),\n\tinstance Text String, instance + String\nimport Text.JSON\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\nimport Cloogle\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\nDEFAULT_INCLUDE_BUILTINS :== True\nDEFAULT_INCLUDE_CORE :== False\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle _ Nothing w = (err CLOOGLE_E_INVALIDINPUT \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey key, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err CLOOGLE_E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions = mbType >>= flip (suggs name) db\n\t\t# w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- mb2list suggestions] w\n\t\t\twith\n\t\t\t\tmb2list Nothing = []; mb2list (Just xs) = xs\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err CLOOGLE_E_NORESULTS \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: Response *World -> *(Response, CacheKey, *World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: RequestCacheKey Int Int Response [Result] *World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page,include_builtins,include_core} db_org\n\t\t# include_builtins = fromJust (include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t\t# include_core = fromJust (include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t\t# db = db_org\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t# db = if include_builtins id (filterLocations (not o isBuiltin)) db\n\t\t# db = if include_core id (filterLocations (not o isCore)) db\n\t\t\twith\n\t\t\t\tisCore :: Location -> Bool\n\t\t\t\tisCore (Builtin _) = False\n\t\t\t\tisCore (Location lib mod _ _ _) = case getModule lib mod db of\n\t\t\t\t\tNothing = False\n\t\t\t\t\t(Just b) = b.is_core\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbPreppedType = prepare_unification True (allTypes db_org)\n\t\t\t<$> (unify >>= parseType o fromString)\n\t\t# usedSynonyms = 'Foldable'.concat (fst <$> mbPreppedType)\n\t\t# mbType = snd <$> mbPreppedType\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t db_org) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n $ getName loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType usedSynonyms Nothing f db_org) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n $ getName loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _ -> isUnifiable t db_org) <$> mbType\n\t\t , (\\n (Location lib mod _ _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n f) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line iclline cls,vs,_,f,et) -> makeFunctionResult name mbType usedSynonyms\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line iclline f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (mbType,lcName) of\n\t\t\t(Nothing, Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t(Just (Type n _),_) = findType n db\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\loc _ _ _ -> toLowerCase (getName loc) == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Search modules\n\t\t# modules = case (mbType, name) of\n\t\t\t(Nothing, Just n) = findModule` (\\_ m _ -> isModNameMatch (size n*2\/3) n m) db\n\t\t\t_ = []\n\t\t# modules = map (makeModuleResult name) modules\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros ++ modules\n\n\tmakeModuleResult :: (Maybe String) (Library, Module, ModuleInfo) -> Result\n\tmakeModuleResult mbName (lib, mod, info)\n\t\t= ModuleResult\n\t\t ( { library = lib\n\t\t , modul = mod\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , distance = modLevenshtein (fromJust mbName) mod\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { module_is_core = info.is_core\n\t\t }\n\t\t )\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line iclline cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" | \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [(map snd ts, map loc ls) \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line iclline t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map snd)) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map snd)) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line iclline m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) [TypeDef] (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype usedsynonyms mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification (unisyns ++ usedsynonyms) <$>\n\t\t (orgsearchtype >>= unify [] unitype)\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(s, map loc ls) \\\\ (_,s,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,iclline,builtin) = case fl of\n\t\t\t(Location l m ln iln f) = (l, m, f, ln, iln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Nothing, Just True)\n\n\t\t(unisyns, unitype) = prepare_unification` False db type\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier unif =\n\t\t\t{ StrUnifier\n\t\t\t| left_to_right = map toStr unif.Unifier.left_to_right\n\t\t\t, right_to_left = map toStr unif.Unifier.right_to_left\n\t\t\t, used_synonyms = [\n\t\t\t\t( concat $ [td.td_name,\" \":intersperse \" \" $ print False td.td_args]\n\t\t\t\t, concat $ print False s)\n\t\t\t\t\\\\ td=:{td_rhs=TDRSynonym s} <- unif.Unifier.used_synonyms]\n\t\t\t}\n\t\twhere\n\t\t\ttoStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (syns, t) = prepare_unification` False db type\n\t\t\t\t# (Just unif) = finish_unification syns <$> unify [] orgsearchtype t\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t) <- allTvas unif | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\tallTvas :: Unifier -> [TVAssignment]\n\t\t\tallTvas unif = unif.Unifier.left_to_right ++ unif.Unifier.right_to_left\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tprepare_unification` :: !Bool !TypeDB -> Type -> ([TypeDef], Type)\n\tprepare_unification` b db = prepare_unification b (allTypes db)\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 +\n\t\tlevenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodLevenshtein :: String Module -> Int\n\tmodLevenshtein s mod\n\t| s == mod = -100\n\t| isMember s path = length path\n\t| otherwise = levenshtein` s mod\n\twhere path = split \".\" mod\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: !Type !TypeDB !ExtendedType -> Bool\n\tisUnifiable t1 db (ET t2 _) = isJust $ unify [] t1 t2`\n\twhere\n\t\t(_, t2`) = (prepare_unification` False db t2)\n\n\tisNameMatch :: !Int !String !String -> Bool\n\tisNameMatch maxdist n1 name\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: name})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModNameMatch :: !Int !String !Module -> Bool\n\tisModNameMatch maxdist name mod\n\t\t= isNameMatch maxdist name mod || isMember name (split \".\" mod)\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: ![String] Location -> Bool\n\tisLibMatch libs (Location lib _ _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch _ (Builtin _) = True\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln iln _) = (lib, mod, ln, iln)\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received (Just r)) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ mkTime mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ mkTime mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nimport StdList\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\nfrom StdFunc import const, flip, id, o, seq\nfrom StdMisc import abort, undef\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable, instance Foldable Maybe\nfrom Data.Func import $\nimport Data.Functor\nimport Data.List\nimport Data.Maybe\nimport Data.Tuple\nimport System.CommandLine\nfrom Text import class Text(concat,trim,indexOf,toLowerCase,split),\n\tinstance Text String, instance + String\nimport Text.JSON\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\nimport Cloogle\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\nDEFAULT_INCLUDE_BUILTINS :== True\nDEFAULT_INCLUDE_CORE :== False\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle _ Nothing w = (err CLOOGLE_E_INVALIDINPUT \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey key, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err CLOOGLE_E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions = mbType >>= flip (suggs name) db\n\t\t# w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- mb2list suggestions] w\n\t\t\twith\n\t\t\t\tmb2list Nothing = []; mb2list (Just xs) = xs\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err CLOOGLE_E_NORESULTS \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: Response *World -> *(Response, CacheKey, *World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: RequestCacheKey Int Int Response [Result] *World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page,include_builtins,include_core} db_org\n\t\t# include_builtins = fromJust (include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t\t# include_core = fromJust (include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t\t# db = db_org\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t# db = if include_builtins id (filterLocations (not o isBuiltin)) db\n\t\t# db = if include_core id (filterLocations (not o isCore)) db\n\t\t\twith\n\t\t\t\tisCore :: Location -> Bool\n\t\t\t\tisCore (Builtin _) = False\n\t\t\t\tisCore (Location lib mod _ _ _) = case getModule lib mod db of\n\t\t\t\t\tNothing = False\n\t\t\t\t\t(Just b) = b.is_core\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbPreppedType = prepare_unification True (allTypes db_org)\n\t\t\t<$> (unify >>= parseType o fromString)\n\t\t# usedSynonyms = 'Foldable'.concat (fst <$> mbPreppedType)\n\t\t# mbType = snd <$> mbPreppedType\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t db_org) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n $ getName loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType usedSynonyms Nothing f db_org) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n $ getName loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _ -> isUnifiable t db_org) <$> mbType\n\t\t , (\\n (Location lib mod _ _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n f) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line iclline cls,vs,_,f,et) -> makeFunctionResult name mbType usedSynonyms\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line iclline f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\loc _ _ _ -> toLowerCase (getName loc) == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Search modules\n\t\t# modules = case (mbType, name) of\n\t\t\t(Nothing, Just n) = findModule` (\\_ m _ -> isModNameMatch (size n*2\/3) n m) db\n\t\t\t_ = []\n\t\t# modules = map (makeModuleResult name) modules\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros ++ modules\n\n\tmakeModuleResult :: (Maybe String) (Library, Module, ModuleInfo) -> Result\n\tmakeModuleResult mbName (lib, mod, info)\n\t\t= ModuleResult\n\t\t ( { library = lib\n\t\t , modul = mod\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , distance = modLevenshtein (fromJust mbName) mod\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { module_is_core = info.is_core\n\t\t }\n\t\t )\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line iclline cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" | \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [(map snd ts, map loc ls) \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line iclline t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map snd)) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map snd)) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line iclline m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) [TypeDef] (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype usedsynonyms mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification (unisyns ++ usedsynonyms) <$>\n\t\t (orgsearchtype >>= unify [] unitype)\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(s, map loc ls) \\\\ (_,s,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,iclline,builtin) = case fl of\n\t\t\t(Location l m ln iln f) = (l, m, f, ln, iln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Nothing, Just True)\n\n\t\t(unisyns, unitype) = prepare_unification` False db type\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier unif =\n\t\t\t{ StrUnifier\n\t\t\t| left_to_right = map toStr unif.Unifier.left_to_right\n\t\t\t, right_to_left = map toStr unif.Unifier.right_to_left\n\t\t\t, used_synonyms = [\n\t\t\t\t( concat $ [td.td_name,\" \":intersperse \" \" $ print False td.td_args]\n\t\t\t\t, concat $ print False s)\n\t\t\t\t\\\\ td=:{td_rhs=TDRSynonym s} <- unif.Unifier.used_synonyms]\n\t\t\t}\n\t\twhere\n\t\t\ttoStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (syns, t) = prepare_unification` False db type\n\t\t\t\t# (Just unif) = finish_unification syns <$> unify [] orgsearchtype t\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t) <- allTvas unif | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\tallTvas :: Unifier -> [TVAssignment]\n\t\t\tallTvas unif = unif.Unifier.left_to_right ++ unif.Unifier.right_to_left\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tprepare_unification` :: !Bool !TypeDB -> Type -> ([TypeDef], Type)\n\tprepare_unification` b db = prepare_unification b (allTypes db)\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 +\n\t\tlevenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodLevenshtein :: String Module -> Int\n\tmodLevenshtein s mod\n\t| s == mod = -100\n\t| isMember s path = length path\n\t| otherwise = levenshtein` s mod\n\twhere path = split \".\" mod\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: !Type !TypeDB !ExtendedType -> Bool\n\tisUnifiable t1 db (ET t2 _) = isJust $ unify [] t1 t2`\n\twhere\n\t\t(_, t2`) = (prepare_unification` False db t2)\n\n\tisNameMatch :: !Int !String !String -> Bool\n\tisNameMatch maxdist n1 name\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: name})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModNameMatch :: !Int !String !Module -> Bool\n\tisModNameMatch maxdist name mod\n\t\t= isNameMatch maxdist name mod || isMember name (split \".\" mod)\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: ![String] Location -> Bool\n\tisLibMatch libs (Location lib _ _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch _ (Builtin _) = True\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln iln _) = (lib, mod, ln, iln)\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received (Just r)) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ mkTime mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ mkTime mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"6a6bf15b2edc73e324b4113de3beebc2ccdf8431","subject":"Copy editing","message":"Copy editing\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\"]\n\t, syntax_code = [\"*...\"]\n\t, syntax_description = \"Annotates a type to be unique.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_eadt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_eadt =\n\t{ syntax_title = \"extensible algebraic data types\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ..\", \":: T = ..\"]\n\t, syntax_description = \"Extensible algebraic data types are ADT's that can be extended in other modules. One module can declare the ADT as extendible by adding the .. constructior. Other modules can then extend it. It is not possible to derive functions for EADTs\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\"]\n\t, syntax_code = [\"*...\"]\n\t, syntax_description = \"Annotates a type to be unique.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"6fb569170aca43bf17a5e223544c0a5ef0b42fb6","subject":"log pongs","message":"log pongs\n","repos":"clean-cloogle\/clean-irc","old_file":"cloogle.icl","new_file":"cloogle.icl","new_contents":"module cloogle\n\nimport GenPrint\nimport IRC\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nfrom Data.Func import $\nfrom Text import class Text(..), instance Text String\n\nimport TCPIP\n\ncommands :: [String]\ncommands = map toString\n\t[NICK \"clooglebot\"\n\t,USER \"cloogle\" 0 \"Cloogle bot\"\n\t,JOIN [(\"#cloogle\", Nothing)]\n\t]\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nKEY :== \"PRIVMSG #cloogle :!\"\n\nsend :: [String] TCP_DuplexChannel *World -> (TCP_DuplexChannel, *World)\nsend [] chan w = (chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = abort \"Could not send request\\n\"\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\nrecv :: TCP_DuplexChannel *World -> (Maybe String, TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = abort \"Halp?\\n\"\n= (toString <$> resp, {sChannel=sChannel,rChannel=rChannel}, w)\n\nmsg :: (String -> IRCCommands)\nmsg = PRIVMSG \"#cloogle\"\n\nprocess :: *File TCP_DuplexChannel *World -> (*File, TCP_DuplexChannel, *World)\nprocess io chan w \n# (mr, chan, w) = recv chan w\n| isNothing mr = process io chan w\n# resp = fromJust mr\n#! io = io <<< (\"Received: \" +++ resp +++ \"\\n\")\n# ind = indexOf KEY resp\n| ind > 0\n\t# cmd = split \" \" $ rtrim $ subString (ind + size KEY) (size resp) resp\n\t#! io = io <<< (\"Received command: \" +++ printToString cmd +++ \"\\n\")\n\t# toSend = case cmd of\n\t\t[\"stop\":_] = Nothing\n\t\t[\"ping\":xs] = Just [msg $ \"pong \" +++ join \" \" xs]\n\t\t[\"help\"] = Just \n\t\t\t[msg \"type !help cmd for command specific help\"\n\t\t\t,msg \"available commands: help, ping\"]\n\t\t[\"help\":c:_] = case c of\n\t\t\t\"help\" = Just [msg \"help [CMD] - I will print general help or the help of CMD\"] \n\t\t\t\"ping\" = Just [msg \"ping [TXT] - I will reply with pong and the optionar TXT\"] \n\t\t\t_ = Just [msg \"Unknown command\"]\n\t\t[c:_] = Just [msg $ join \" \" [\"unknown command: \" , c, \", type !help to get help\"]]\n\t| isNothing toSend = (io, chan, w)\n\t# (chan, w) = send (map toString $ fromJust toSend) chan w\n\t= process io chan w\n| indexOf \"PING :\" resp > 0\n\t# cmd = rtrim $ subString (indexOf \"PING :\" resp + size \"PING :\") (size resp) resp\n\t#! io <<< (toString $ PONG cmd Nothing) <<< \"\\n\"\n\t# (chan, w) = send [toString $ PONG cmd Nothing] chan w\n\t= process io chan w\n= process io chan w\n\nStart :: *World -> *World\nStart w\n# (io, w) = stdio w\n# (ip, w) = lookupIPAddress SERVER w\n| isNothing ip = abort $ \"DNS lookup for \" +++ SERVER +++ \" failed\\n\"\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, 6667) w\n| rpt == TR_Expired = abort $ \"Connection to \" +++ SERVER +++ \" timed out\\n\"\n| rpt == TR_NoSuccess = abort $ \"Could not connect to \" +++ SERVER +++ \"\\n\"\n# chan = fromJust chan\n# (chan, w) = send commands chan w\n# (io, chan, w) = process io chan w\n# ({sChannel,rChannel}, w) = send [toString $ QUIT Nothing] chan w\n# (_, w) = fclose io w\n= closeChannel sChannel (closeRChannel rChannel w)\n","old_contents":"module cloogle\n\nimport GenPrint\nimport IRC\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nfrom Data.Func import $\nfrom Text import class Text(..), instance Text String\n\nimport TCPIP\n\ncommands :: [String]\ncommands = map toString\n\t[NICK \"clooglebot\"\n\t,USER \"cloogle\" 0 \"Cloogle bot\"\n\t,JOIN [(\"#cloogle\", Nothing)]\n\t]\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nKEY :== \"PRIVMSG #cloogle :!\"\n\nsend :: [String] TCP_DuplexChannel *World -> (TCP_DuplexChannel, *World)\nsend [] chan w = (chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = abort \"Could not send request\\n\"\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\nrecv :: TCP_DuplexChannel *World -> (Maybe String, TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = abort \"Halp?\\n\"\n= (toString <$> resp, {sChannel=sChannel,rChannel=rChannel}, w)\n\nmsg :: (String -> IRCCommands)\nmsg = PRIVMSG \"#cloogle\"\n\nprocess :: *File TCP_DuplexChannel *World -> (*File, TCP_DuplexChannel, *World)\nprocess io chan w \n# (mr, chan, w) = recv chan w\n| isNothing mr = process io chan w\n# resp = fromJust mr\n#! io = io <<< (\"Received: \" +++ resp +++ \"\\n\")\n# ind = indexOf KEY resp\n| ind > 0\n\t# cmd = split \" \" $ rtrim $ subString (ind + size KEY) (size resp) resp\n\t#! io = io <<< (\"Received command: \" +++ printToString cmd +++ \"\\n\")\n\t# toSend = case cmd of\n\t\t[\"stop\":_] = Nothing\n\t\t[\"ping\":_] = Just [msg \"pong\"]\n\t\t[\"help\"] = Just \n\t\t\t[msg \"type !help cmd for command specific help\"\n\t\t\t,msg \"available commands: help, ping\"]\n\t\t[\"help\":c:_] = case c of\n\t\t\t\"help\" = Just [msg \"I will print help text\"] \n\t\t\t\"ping\" = Just [msg \"I will reply with pong\"] \n\t\t\t_ = Just [msg \"Unknown command\"]\n\t\t[c:_] = Just [msg $ join \" \" [\"unknown command: \" , c, \", type !help to get help\"]]\n\t| isNothing toSend = (io, chan, w)\n\t# (chan, w) = send (map toString $ fromJust toSend) chan w\n\t= process io chan w\n| indexOf \"PING :\" resp > 0\n\t# cmd = rtrim $ subString (indexOf \"PING :\" resp + size \"PING :\") (size resp) resp\n\t# (chan, w) = send [toString $ PONG cmd Nothing] chan w\n\t= process io chan w\n= process io chan w\n\nStart :: *World -> *World\nStart w\n# (io, w) = stdio w\n# (ip, w) = lookupIPAddress SERVER w\n| isNothing ip = abort $ \"DNS lookup for \" +++ SERVER +++ \" failed\\n\"\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, 6667) w\n| rpt == TR_Expired = abort $ \"Connection to \" +++ SERVER +++ \" timed out\\n\"\n| rpt == TR_NoSuccess = abort $ \"Could not connect to \" +++ SERVER +++ \"\\n\"\n# chan = fromJust chan\n# (chan, w) = send commands chan w\n# (io, chan, w) = process io chan w\n# ({sChannel,rChannel}, w) = send [toString $ QUIT Nothing] chan w\n# (_, w) = fclose io w\n= closeChannel sChannel (closeRChannel rChannel w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"fd6e2ee6ce73610ba35ffa827c46acc41d060159","subject":"Parse bots in config","message":"Parse bots in config\n","repos":"ErinvanderVeen\/Clone,ErinvanderVeen\/Clone","old_file":"src\/Config.icl","new_file":"src\/Config.icl","new_contents":"implementation module Config\n\nimport Bot\nimport System.File, Text.JSON, Data.Maybe\nfrom Data.Error import isError, fromOk\nfrom StdMisc import abort\nfrom StdFile import instance FileSystem World\n\nparseConfig :: !*World -> (Config, *World)\nparseConfig w\n# (configString, w) = readConfig w\n# node = fromString configString\n# botsArray = jsonQuery \"bots\" node\n| isNothing botsArray = abort \"Could not find \\\"bots\\\" in config file\"\n# botsArray = fromJSONArray (fromJust botsArray)\n| isNothing botsArray = abort \"Could not get bots array from config file\"\n# botsArray = map toBot (fromJust botsArray)\n# config = { Config | bots = botsArray }\n= (config, w)\nwhere\n\treadConfig :: !*World -> (String, *World)\n\treadConfig w\n\t# (result, w) = readFile \"config\" w\n\t| isError result = abort \"Could not read from config file\"\n\t# result = fromOk result\n\t= (result, w)\n\n\tfromJSONArray :: JSONNode -> Maybe [JSONNode]\n\tfromJSONArray (JSONArray x) = Just x\n\tfromJSONArray _ = Nothing\n\n\ttoBot :: JSONNode -> Bot\n\ttoBot node = {Bot | name=fromJust (jsonQuery \"name\" node),\n\t children=fromJust (jsonQuery \"children\" node),\n\t interval=fromJust (jsonQuery \"interval\" node)\n\t }\n\ttoBot _ = abort \"Could not parse bot in config file\"\n","old_contents":"implementation module Config\n\nimport Bot\nimport System.File, Text.JSON, Data.Maybe\nfrom Data.Error import isError, fromOk\nfrom StdMisc import abort\nfrom StdFile import instance FileSystem World\n\nparseConfig :: !*World -> (Config, *World)\nparseConfig w\n# (configString, w) = readConfig w\n# node = fromString configString\n# botsArray = jsonQuery \"bots\" node\n| isNothing botsArray = abort \"Could not find \\\"bots\\\" in config file\"\n# botsArray = fromJSONArray (fromJust botsArray)\n| isNothing botsArray = abort \"Could not get bots array from config file\"\n# botsArray = map toBot (fromJust botsArray)\n# config = { Config | bots = botsArray }\n= (config, w)\nwhere\n\treadConfig :: !*World -> (String, *World)\n\treadConfig w\n\t# (result, w) = readFile \"config\" w\n\t| isError result = abort \"Could not read from config file\"\n\t# result = fromOk result\n\t= (result, w)\n\n\tfromJSONArray :: JSONNode -> Maybe [JSONNode]\n\tfromJSONArray (JSONArray x) = Just x\n\tfromJSONArray _ = Nothing\n\n\ttoBot :: JSONNode -> Bot\n\ttoBot (JSONObject _) = abort \"Not yet implemented\"\n\ttoBot _ = abort \"Could not parse bot in config file\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"f074af399299d040f01463221e90b5534e6833e2","subject":"Add functional dependencies as syntax builtin","message":"Add functional dependencies as syntax builtin\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle","old_file":"backend\/BuiltinSyntax.icl","new_file":"backend\/BuiltinSyntax.icl","new_contents":"implementation module BuiltinSyntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle\n\nimport CloogleDB\n\nimport Builtins\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class c a ~b\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental)\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"class plus a b c :: a b -> c\"\n\t\t, \"instance plus Int Int Int where plus x y = x + y\"\n\t\t, \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\"\n\t\t, \"instance plus Int Int Int where plus x y = x + y\"\n\t\t, \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module BuiltinSyntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle\n\nimport CloogleDB\n\nimport Builtins\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"645fd3290b69fa7d47a12296adcd1035c438bcf9","subject":"Pass Bot.vars to Bot on execution","message":"Pass Bot.vars to Bot on execution\n","repos":"ErinvanderVeen\/Clone,ErinvanderVeen\/Clone","old_file":"src\/Bot.icl","new_file":"src\/Bot.icl","new_contents":"implementation module Bot\n\nimport StdString\nfrom StdMisc import abort\nfrom StdTuple import snd\nfrom StdList import isEmpty\n\nimport System.Process, Data.Error, System._Posix\n\nrunBot :: Bot (Maybe String) *World -> (Maybe String, *World)\nrunBot bot input world\n# (err, world) = runProcessIO (\".\/\" +++ bot.exe) (flattenBotVars bot.vars) (Just \"bots\") world\n| isError err = abort (\"Could not start bot: \" +++ bot.name +++ \"\\n\" +++ snd (fromError err))\n# (handle, io) = fromOk err\n# (err, world) = writePipe (fromMaybe \"\" input) io.stdIn world\n| isError err = abort (\"Could not write to stdIn of \" +++ bot.name +++ \"\\n\" +++ snd (fromError err))\n# (err, world) = closePipe io.stdIn world\n| isError err = abort \"Could not close stdIn pipe\"\n# (err, world) = waitForProcess handle world\n# (result, world) = readStdOut io.stdOut world\n# (err, world) = closePipe io.stdOut world\n| isError err = abort \"Could not close stdOut pipe\"\n# (err, world) = closePipe io.stdErr world\n| isError err = abort \"Could not close stdErr pipe\"\n| isEmpty bot.children = (Nothing, world)\n= (result, world)\nwhere\n\treadStdOut :: ReadPipe !*World -> (Maybe String, *World)\n\treadStdOut pipe world\n\t# (err, world) = readPipeNonBlocking pipe world\n\t| isError err = abort \"Could not read stdOut\"\n\t# result = fromOk err\n\t| result == \"\" = (Nothing, world)\n\t= (Just result, world)\n\n\tflattenBotVars :: [(String, String)] -> [String]\n\tflattenBotVars [] = []\n\tflattenBotVars [(a, b) : vs] = [a, b : flattenBotVars vs]\n","old_contents":"implementation module Bot\n\nimport StdString\nfrom StdMisc import abort\nfrom StdTuple import snd\nfrom StdList import isEmpty\n\nimport System.Process, Data.Error, System._Posix\n\nrunBot :: Bot (Maybe String) *World -> (Maybe String, *World)\nrunBot bot input world\n# (err, world) = runProcessIO (\".\/\" +++ bot.exe) [] (Just \"bots\") world\n| isError err = abort (\"Could not start bot: \" +++ bot.name +++ \"\\n\" +++ snd (fromError err))\n# (handle, io) = fromOk err\n# (err, world) = writePipe (fromMaybe \"\" input) io.stdIn world\n| isError err = abort (\"Could not write to stdIn of \" +++ bot.name +++ \"\\n\" +++ snd (fromError err))\n# (err, world) = closePipe io.stdIn world\n| isError err = abort \"Could not close stdIn pipe\"\n# (err, world) = waitForProcess handle world\n# (result, world) = readStdOut io.stdOut world\n# (err, world) = closePipe io.stdOut world\n| isError err = abort \"Could not close stdOut pipe\"\n# (err, world) = closePipe io.stdErr world\n| isError err = abort \"Could not close stdErr pipe\"\n| isEmpty bot.children = (Nothing, world)\n= (result, world)\nwhere\n\treadStdOut :: ReadPipe !*World -> (Maybe String, *World)\n\treadStdOut pipe world\n\t# (err, world) = readPipeNonBlocking pipe world\n\t| isError err = abort \"Could not read stdOut\"\n\t# result = fromOk err\n\t| result == \"\" = (Nothing, world)\n\t= (Just result, world)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"03bc56cf91af878204599300e4f4e8dae1761a2e","subject":"Typo in description of derive","message":"Typo in description of derive\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... [| ...] :: ... \", \"derive ... ... [of ... [with ...]]\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, EX \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, EXs \"macro\" $ \"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context\\n\" +\n\t\t \"gFun{|CONS of {gcd_arity}|} with f _ \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ... [| ...]\", \"derive ... ... [of ... [with ...]]\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, EX \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, EXs \"macro\" $ \"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context\\n\" +\n\t\t \"gFun{|CONS of {gcd_arity}|} with f _ \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"d7c9fb45c091aecd465d1f99d25c7d7835c26c0f","subject":"Resolve #164 (only cache slow queries); add microseconds to cloogle.log","message":"Resolve #164 (only cache slow queries); add microseconds to cloogle.log\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat,toLowerCase), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\nCACHE_NS_THRESHOLD :== 40000000\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Maybe [String]\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w)\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", (Nothing,0), db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t#! (start,w) = nsTime w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond start Nothing {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond start Nothing (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond start Nothing (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond start Nothing (err InvalidType \"Couldn't parse type\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond start (Just key) response db w\n\twhere\n\t\trespond :: !Timespec !(Maybe RequestCacheKey) !Response !*CloogleDB !*World ->\n\t\t\t*(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\t\trespond start key r db w\n\t\t#! (end,w) = nsTime w\n\t\t#! duration = 1000000000 * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec\n\t\t#! cache = duration > CACHE_NS_THRESHOLD\n\t\t= (r, (if cache (cacheKey <$> key) Nothing, duration \/ 1000), db, case (cache,key) of\n\t\t\t(True,Just k) -> writeCache LongTerm k r w\n\t\t\t_ -> w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World)\n\treloadCache (db,w)\n\t# (ks,w) = allCacheKeys LongTerm w\n\t= loop ks db w\n\twhere\n\t\tloop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World)\n\t\tloop [] db w = (db,w)\n\t\tloop [k:ks] db w\n\t\t# w = removeFromCache LongTerm k w\n\t\t# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w\n\t\t# db = resetDB db\n\t\t= loop ks db w\n\n\tdoInBackground :: (*a -> *a) *a -> *a\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: MicroSeconds :== Int\n\n:: LogMessage` :== LogMessage (Maybe Request) Response (Maybe CacheKey, MicroSeconds)\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, microseconds :: Int\n\t, request :: Maybe Request\n\t, cachekey :: Maybe String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response (ck,us)) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, microseconds = us\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat,toLowerCase), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Maybe [String]\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w)\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, CacheKey, !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", \"\", db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond key {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond key (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond key (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond key (err InvalidType \"Couldn't parse type\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond key response db w\n\twhere\n\t\trespond :: !RequestCacheKey !Response !*CloogleDB !*World -> *(!Response, !CacheKey, !*CloogleDB, !*World)\n\t\trespond key r db w = (r, cacheKey key, db, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World)\n\treloadCache (db,w)\n\t# (ks,w) = allCacheKeys LongTerm w\n\t= loop ks db w\n\twhere\n\t\tloop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World)\n\t\tloop [] db w = (db,w)\n\t\tloop [k:ks] db w\n\t\t# w = removeFromCache LongTerm k w\n\t\t# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w\n\t\t# db = resetDB db\n\t\t= loop ks db w\n\n\tdoInBackground :: (*a -> *a) *a -> *a\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"2b42fddd59e332c6a9cac68dec97d0e28db5d11b","subject":"Fix syntax of & slight changes to previous 2 commits","message":"Fix syntax of & slight changes to previous 2 commits\n","repos":"clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org","old_file":"backend\/Builtins.icl","new_file":"backend\/Builtins.icl","new_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [(Location, FunctionEntry)]\nbuiltin_functions\n\t= [ ( Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , {zero & fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []}\n\t )\n\t , ( Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , {zero & fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]}\n\t )\n\t ]\n\nbuiltin_classes :: [(Location, ClassEntry)]\nbuiltin_classes\n\t= [ ( Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , { ce_vars=[\"v\"]\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t }\n\t )\n\t ]\n\nbuiltin_types :: [(Location, TypeDefEntry)]\nbuiltin_types\n\t= [ ( Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , { deft\n\t & tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Int\"})\n\t , ( Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Real\"})\n\t , ( Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Char\"})\n\t , ( Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"String\",\n\t tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], {deft & tde_typedef.td_name = \"Dynamic\"})\n\t , ( Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"File\"})\n\t , ( Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"World\",\n\t tde_typedef.td_uniq = True,\n\t tde_doc = Just $ TypeDoc\n\t (Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\")\n\t [] Nothing})\n\t , ( Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"], {deft & tde_typedef.td_name = \"(->)\",\n\t tde_typedef.td_args = [Var \"a\", Var \"b\"],\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\")\n\t [\"The argument type\", \"The result type\"]\n\t Nothing})\n\t , ( Builtin \"()\" [], {deft & tde_typedef.td_name=\"_Unit\",\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The void \/ unit type.\")\n\t [] Nothing,\n\t tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]})\n\t : lists\n\t ++ arrays\n\t ++ tuples\n\t ]\nwhere\n\tdeft = {tde_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract Nothing}, tde_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> (Location, TypeDefEntry)\n\t\tmake_list k s = (Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description)\n\t\t\t\t[\"The type of the list elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> (Location, TypeDefEntry)\n\t\tmake_array k = (Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description)\n\t\t\t\t[\"The type of the array elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> (Location, TypeDefEntry)\n\t\tmake_tuple n = (Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t \"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t \"Clean supports tuples of arity 2 to 32.\")\n\t\t\t\t[] Nothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_class = ([\"class\"],\n\t{ syntax_title = \"class\"\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t})\n\nbs_code = ([\"code\", \"inline\", \"code inline\"],\n\t{ syntax_title = \"ABC code\"\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t})\n\nbs_generic = ([\"generic\", \"derive\", \"of\", \"{|*|}\"], \/\/ This * matches everything, which is intentional\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_instance = ([\"instance\"],\n\t{ syntax_title = \"instance\"\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t})\n\nbs_lambda = ([\"lambda\", \"\\\\*\", \"->\", \".\"],\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t})\n\nbs_layout_rule = ([\";\", \"{\", \"}\"],\n\t{ syntax_title = \"layout rule\"\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_list_expressions = ([\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"],\n\t{ syntax_title = \"list expression\"\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t})\n\nbs_macro = ([\":==\", \"macro\"],\n\t{ syntax_title = \"macro\"\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t})\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_newtype = ([\"=:\", \"newtype\"],\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t})\n\nbs_selection_array = ([\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"],\n\t{ syntax_title = \"array selection\"\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t})\nbs_selection_array_unique = ([\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"],\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t})\nbs_selection_record = ([\".\"],\n\t{ syntax_title = \"record selection\"\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t})\nbs_selection_record_unique = ([\"!\"],\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n\nbs_zf = ([\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"],\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t})\n","old_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [(Location, FunctionEntry)]\nbuiltin_functions\n\t= [ ( Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , {zero & fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []}\n\t )\n\t , ( Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , {zero & fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]}\n\t )\n\t ]\n\nbuiltin_classes :: [(Location, ClassEntry)]\nbuiltin_classes\n\t= [ ( Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , { ce_vars=[\"v\"]\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t }\n\t )\n\t ]\n\nbuiltin_types :: [(Location, TypeDefEntry)]\nbuiltin_types\n\t= [ ( Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , { deft\n\t & tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Int\"})\n\t , ( Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Real\"})\n\t , ( Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Char\"})\n\t , ( Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"String\",\n\t tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], {deft & tde_typedef.td_name = \"Dynamic\"})\n\t , ( Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"File\"})\n\t , ( Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"World\",\n\t tde_typedef.td_uniq = True,\n\t tde_doc = Just $ TypeDoc\n\t (Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\")\n\t [] Nothing})\n\t , ( Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"], {deft & tde_typedef.td_name = \"(->)\",\n\t tde_typedef.td_args = [Var \"a\", Var \"b\"],\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\")\n\t [\"The argument type\", \"The result type\"]\n\t Nothing})\n\t , ( Builtin \"()\" [], {deft & tde_typedef.td_name=\"_Unit\",\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The void \/ unit type.\")\n\t [] Nothing,\n\t tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]})\n\t : lists\n\t ++ arrays\n\t ++ tuples\n\t ]\nwhere\n\tdeft = {tde_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract Nothing}, tde_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> (Location, TypeDefEntry)\n\t\tmake_list k s = (Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description)\n\t\t\t\t[\"The type of the list elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> (Location, TypeDefEntry)\n\t\tmake_array k = (Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description)\n\t\t\t\t[\"The type of the array elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> (Location, TypeDefEntry)\n\t\tmake_tuple n = (Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t \"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t \"Clean supports tuples of arity 2 to 32.\")\n\t\t\t\t[] Nothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_class = ([\"class\"],\n\t{ syntax_title = \"class\"\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t})\n\nbs_code = ([\"code\", \"inline\", \"code inline\"],\n\t{ syntax_title = \"ABC code\"\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t})\n\nbs_generic = ([\"generic\", \"derive\", \"of\", \"{|*|}\"], \/\/ This * matches everything, which is intentional\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_instance = ([\"instance\"],\n\t{ syntax_title = \"instance\"\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t})\n\nbs_lambda = ([\"lambda\", \"\\\\*\", \"->\", \".\"],\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t})\n\nbs_layout_rule = ([\";\", \"{\", \"}\"],\n\t{ syntax_title = \"layout rule\"\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_list_expressions = ([\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"],\n\t{ syntax_title = \"list expression\"\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t})\n\nbs_macro = ([\":==\", \"macro\"],\n\t{ syntax_title = \"macro\"\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t})\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_pattern_newtype = ([\"=:\"],\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_code = [\":: ... =: ...\"]\n\t, syntax_description = \"A newtype is a type synonym at runtime but treated as a real type at compiletime.\\n\"\n\t + \"This allows the creation of instances and speeds the program up.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t[ EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t})\n\nbs_selection_array = ([\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"],\n\t{ syntax_title = \"array selection\"\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t})\nbs_selection_array_unique = ([\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"],\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t})\nbs_selection_record = ([\".\"],\n\t{ syntax_title = \"record selection\"\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t})\nbs_selection_record_unique = ([\"!\"],\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n\nbs_zf = ([\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"],\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t})\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"f9e2851fe76d135018eb4dd2c2b3741274349ea6","subject":"Fix the generic dependency example","message":"Fix the generic dependency example","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\"\n\t\t, \"A generic function can only contain a generic context written with a different syntax.\"\n\t\t, \"The generic dependency is written without the kind specification and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int\" \/\/ Generic dependency\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\"\n\t\t, \"A generic function can only contain a generic context written with a different syntax.\"\n\t\t, \"The generic dependency is written without the kind specification and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a\" \/\/ Generic dependency\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"4935dd91d74b536a1d1f3d0f456c3ee19b2d8f44","subject":"Add newtype to the builtins database","message":"Add newtype to the builtins database\n","repos":"dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/Builtins.icl","new_file":"backend\/Builtins.icl","new_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [(Location, FunctionEntry)]\nbuiltin_functions\n\t= [ ( Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , {zero & fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []}\n\t )\n\t , ( Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , {zero & fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]}\n\t )\n\t ]\n\nbuiltin_classes :: [(Location, ClassEntry)]\nbuiltin_classes\n\t= [ ( Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , { ce_vars=[\"v\"]\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t }\n\t )\n\t ]\n\nbuiltin_types :: [(Location, TypeDefEntry)]\nbuiltin_types\n\t= [ ( Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , { deft\n\t & tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Int\"})\n\t , ( Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Real\"})\n\t , ( Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Char\"})\n\t , ( Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"String\",\n\t tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], {deft & tde_typedef.td_name = \"Dynamic\"})\n\t , ( Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"File\"})\n\t , ( Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"World\",\n\t tde_typedef.td_uniq = True,\n\t tde_doc = Just $ TypeDoc\n\t (Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\")\n\t [] Nothing})\n\t , ( Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"], {deft & tde_typedef.td_name = \"(->)\",\n\t tde_typedef.td_args = [Var \"a\", Var \"b\"],\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\")\n\t [\"The argument type\", \"The result type\"]\n\t Nothing})\n\t , ( Builtin \"()\" [], {deft & tde_typedef.td_name=\"_Unit\",\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The void \/ unit type.\")\n\t [] Nothing,\n\t tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]})\n\t : lists\n\t ++ arrays\n\t ++ tuples\n\t ]\nwhere\n\tdeft = {tde_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract Nothing}, tde_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> (Location, TypeDefEntry)\n\t\tmake_list k s = (Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description)\n\t\t\t\t[\"The type of the list elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> (Location, TypeDefEntry)\n\t\tmake_array k = (Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description)\n\t\t\t\t[\"The type of the array elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> (Location, TypeDefEntry)\n\t\tmake_tuple n = (Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t \"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t \"Clean supports tuples of arity 2 to 32.\")\n\t\t\t\t[] Nothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_class = ([\"class\"],\n\t{ syntax_title = \"class\"\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t})\n\nbs_code = ([\"code\", \"inline\", \"code inline\"],\n\t{ syntax_title = \"ABC code\"\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t})\n\nbs_generic = ([\"generic\", \"derive\", \"of\", \"{|*|}\"], \/\/ This * matches everything, which is intentional\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_instance = ([\"instance\"],\n\t{ syntax_title = \"instance\"\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t})\n\nbs_lambda = ([\"lambda\", \"\\\\*\", \"->\", \".\"],\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t})\n\nbs_layout_rule = ([\";\", \"{\", \"}\"],\n\t{ syntax_title = \"layout rule\"\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_list_expressions = ([\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"],\n\t{ syntax_title = \"list expression\"\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t})\n\nbs_macro = ([\":==\", \"macro\"],\n\t{ syntax_title = \"macro\"\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t})\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"newtype definition (experimental)\"\n\t, syntax_code = [\":: ... =: T c\"]\n\t, syntax_description = \"Define a newtype, a newtype is a type synonym that is treated as a real type.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"Function\" \":: T = T Int\"\n\t\t]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t})\n\nbs_selection_array = ([\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"],\n\t{ syntax_title = \"array selection\"\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t})\nbs_selection_array_unique = ([\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"],\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t})\nbs_selection_record = ([\".\"],\n\t{ syntax_title = \"record selection\"\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t})\nbs_selection_record_unique = ([\"!\"],\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n\nbs_zf = ([\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"],\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t})\n","old_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [(Location, FunctionEntry)]\nbuiltin_functions\n\t= [ ( Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , {zero & fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []}\n\t )\n\t , ( Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , {zero & fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]}\n\t )\n\t ]\n\nbuiltin_classes :: [(Location, ClassEntry)]\nbuiltin_classes\n\t= [ ( Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , { ce_vars=[\"v\"]\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t }\n\t )\n\t ]\n\nbuiltin_types :: [(Location, TypeDefEntry)]\nbuiltin_types\n\t= [ ( Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , { deft\n\t & tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Int\"})\n\t , ( Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Real\"})\n\t , ( Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Char\"})\n\t , ( Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"String\",\n\t tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], {deft & tde_typedef.td_name = \"Dynamic\"})\n\t , ( Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"File\"})\n\t , ( Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"World\",\n\t tde_typedef.td_uniq = True,\n\t tde_doc = Just $ TypeDoc\n\t (Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\")\n\t [] Nothing})\n\t , ( Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"], {deft & tde_typedef.td_name = \"(->)\",\n\t tde_typedef.td_args = [Var \"a\", Var \"b\"],\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\")\n\t [\"The argument type\", \"The result type\"]\n\t Nothing})\n\t , ( Builtin \"()\" [], {deft & tde_typedef.td_name=\"_Unit\",\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The void \/ unit type.\")\n\t [] Nothing,\n\t tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]})\n\t : lists\n\t ++ arrays\n\t ++ tuples\n\t ]\nwhere\n\tdeft = {tde_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract Nothing}, tde_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> (Location, TypeDefEntry)\n\t\tmake_list k s = (Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description)\n\t\t\t\t[\"The type of the list elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> (Location, TypeDefEntry)\n\t\tmake_array k = (Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description)\n\t\t\t\t[\"The type of the array elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> (Location, TypeDefEntry)\n\t\tmake_tuple n = (Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t \"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t \"Clean supports tuples of arity 2 to 32.\")\n\t\t\t\t[] Nothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_class = ([\"class\"],\n\t{ syntax_title = \"class\"\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t})\n\nbs_code = ([\"code\", \"inline\", \"code inline\"],\n\t{ syntax_title = \"ABC code\"\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t})\n\nbs_generic = ([\"generic\", \"derive\", \"of\", \"{|*|}\"], \/\/ This * matches everything, which is intentional\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_instance = ([\"instance\"],\n\t{ syntax_title = \"instance\"\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t})\n\nbs_lambda = ([\"lambda\", \"\\\\*\", \"->\", \".\"],\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t})\n\nbs_layout_rule = ([\";\", \"{\", \"}\"],\n\t{ syntax_title = \"layout rule\"\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_list_expressions = ([\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"],\n\t{ syntax_title = \"list expression\"\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t})\n\nbs_macro = ([\":==\", \"macro\"],\n\t{ syntax_title = \"macro\"\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t})\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t})\n\nbs_selection_array = ([\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"],\n\t{ syntax_title = \"array selection\"\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t})\nbs_selection_array_unique = ([\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"],\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t})\nbs_selection_record = ([\".\"],\n\t{ syntax_title = \"record selection\"\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t})\nbs_selection_record_unique = ([\"!\"],\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n\nbs_zf = ([\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"],\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t})\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"18d57639dc20cbcb445a62c8b23bb7263f6a8072","subject":"Fix #14","message":"Fix #14\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"builddb.icl","new_file":"builddb.icl","new_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}\n\n\/\/ StdEnv\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nfrom Text import class Text(concat), instance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String\nimport CoclUtils\n\n\/\/ frontend\n\/\/import Heap, compile, parse, predef\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents), ::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr, ::Position(NoPos), ::Module{mod_ident,mod_defs}, ::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class), ::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType, ::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_types}, ::Type, ::ClassDef{class_ident,class_args}, ::TypeVar\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = {\n\thelp :: Bool,\n\tversion :: Bool,\n\troot :: String,\n\tlibs :: [String]}\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ \"StdEnv\"\n\t , \"StdLib\"\n\t , \"ArgEnv\"\n\t , \"Directory\"\n\t , \"Dynamics\"\n\t , \"Gast\"\n\t , \"Generics\"\n\t , \"MersenneTwister\"\n\t , \"TCPIP\"\n\t , \"clean-platform\/OS-Independent\"\n\t , \"clean-platform\/OS-Linux\"\n\t , \"clean-platform\/OS-Linux-32\"\n\t , \"clean-platform\/OS-Linux-64\"\n\t , \"clean-platform\/OS-Mac\"\n\t , \"clean-platform\/OS-Posix\"\n\t , \"clean-platform\/OS-Windows\"\n\t , \"clean-platform\/OS-Windows-32\"\n\t , \"clean-platform\/OS-Windows-64\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > builddb.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (mods, w) = findModules` cli.libs cli.root w\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# f = 'DB'.saveDb db f\n\t= fclose f w\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String)] 'DB'.TypeDB *DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib cache db w\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[x:c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\/\/ Libraries Library Module\nfindModules` :: ![String] !String !*World -> *(![(String,String)], !*World)\nfindModules` [] _ w = ([], w)\nfindModules` [lib:libs] root w\n#! (mods, w) = findModules lib root w\n#! (moremods, w) = findModules` libs root w\n= (removeDup (mods ++ moremods), w)\n\nfindModules :: !String !String !*World -> *(![(String,String)], !*World)\nfindModules lib root w\n#! (fps, w) = readDirectory (root +++ \"\/\" +++ lib) w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s->(lib, s%(0,size s-5))) $ filter isDclModule fps\n#! (moremods, w) = findModules` (map ((+++) (lib+++\"\/\")) (filter isDirectory fps)) root w\n= (removeDup (mods ++ moremods), w)\nwhere\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String String String *DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib cache db w\n# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ \".dcl\"\n# (ok,f,w) = fopen filename FReadText w\n| not ok = abort (\"Couldn't open file \" +++ filename +++ \".\\n\")\n# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n cache = {cache & hash_table=ht}\n# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" False mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n cache = {cache & hash_table=ht}\n# (ok,w) = fclose f w\n| not ok = abort (\"Couldn't close file \" +++ filename +++ \".\\n\")\n# mod = pm.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putTypes (pd_typespecs lib mod pm.mod_defs) db\n# db = 'DB'.putInstancess (pd_instances pm.mod_defs) db\n# db = 'DB'.putClasses (pd_classes lib mod pm.mod_defs) db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_typespecs :: String String [ParsedDefinition] -> [('DB'.FunctionLocation, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod pds\n\t\t= [('DB'.FL lib mod id_name, 'DB'.ET ('T'.toType t) {te_priority=toPrio p})\n\t\t \\\\ PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs <- pds]\n\twhere\n\t\ttoPrio :: Priority -> Maybe 'DB'.TE_Priority\n\t\ttoPrio (Prio LeftAssoc i) = Just $ 'DB'.LeftAssoc i\n\t\ttoPrio (Prio RightAssoc i) = Just $ 'DB'.RightAssoc i\n\t\ttoPrio (Prio NoAssoc i) = Just $ 'DB'.NoAssoc i\n\t\ttoPrio _ = Nothing\n\n\tpd_instances :: [ParsedDefinition] -> [('DB'.Class, ['DB'.Type])]\n\tpd_instances pds\n\t\t= [(pi_ident.id_name, map 'T'.toType pi_types)\n\t\t \\\\ PD_Instance {pim_pi={pi_ident,pi_types}} <- pds]\n\n\tpd_classes :: String String [ParsedDefinition]\n\t\t-> [('DB'.ClassLocation, ['T'.TypeVar], [('DB'.FunctionName, 'DB'.ExtendedType)])]\n\tpd_classes lib mod pds\n\t# pds = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) pds\n\t= map (\\(PD_Class {class_ident={id_name},class_args} pds)\n\t\t-> let typespecs = pd_typespecs lib mod pds\n\t\tin ('DB'.CL lib mod id_name, map 'T'.toTypeVar class_args, \n\t\t\t[(f,et) \\\\ ('DB'.FL _ _ f, et) <- typespecs])) pds\n\nunigroups :: (Type Type -> Bool) [(a,Type)] -> [([a],Type)]\nunigroups f ts = unigroups` ts []\nwhere\n\tunigroups` [] groups = groups\n\tunigroups` [(a,t):ts] [] = unigroups` ts [([a],t)]\n\tunigroups` [(a,t):ts] [(ns,ut):groups]\n\t| f t ut\t= unigroups` ts [([a:ns],ut):groups]\n\t| otherwise = unigroups` ts [(ns,ut):unigroups` [(a,t)] groups]\n\n(<+) infixr 5 :: a b -> [String] | print a & print b\n(<+) a b = print a ++ print b\n\njoin :: a [b] -> [String] | print a & print b\njoin _ [] = []\njoin a [b:[]] = print b\njoin a [b:bs] = b <+ a <+ join a bs\n\nalignl :: Int a -> [String] | print a\nalignl i s\n# s = print s\n# len = sum (map size s)\n| len >= i = s\n| otherwise = s ++ [{' ' \\\\ i <- [0..i-len]}]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","old_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}\n\n\/\/ StdEnv\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nfrom Text import class Text(concat), instance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String\nimport CoclUtils\n\n\/\/ frontend\n\/\/import Heap, compile, parse, predef\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents), ::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr, ::Position(NoPos), ::Module{mod_ident,mod_defs}, ::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class), ::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType, ::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_types}, ::Type, ::ClassDef{class_ident,class_args}, ::TypeVar\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = {\n\thelp :: Bool,\n\tversion :: Bool,\n\troot :: String,\n\tlibs :: [String]}\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ \"StdEnv\"\n\t , \"StdLib\"\n\t , \"ArgEnv\"\n\t , \"Directory\"\n\t , \"Dynamics\"\n\t , \"Gast\"\n\t , \"Generics\"\n\t , \"MersenneTwister\"\n\t , \"TCPIP\"\n\t , \"clean-platform\/OS-Independent\"\n\t , \"clean-platform\/OS-Linux\"\n\t , \"clean-platform\/OS-Linux-32\"\n\t , \"clean-platform\/OS-Linux-64\"\n\t , \"clean-platform\/OS-Mac\"\n\t , \"clean-platform\/OS-Posix\"\n\t , \"clean-platform\/OS-Windows\"\n\t , \"clean-platform\/OS-Windows-32\"\n\t , \"clean-platform\/OS-Windows-64\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > builddb.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (mods, w) = findModules` cli.libs cli.root w\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop mods 'DB'.newDb cache w\n\t# f = 'DB'.saveDb db f\n\t= fclose f w\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: [(String,String)] 'DB'.TypeDB *DclCache *World -> *('DB'.TypeDB, *World)\n\tloop [] db _ w = (db,w)\n\tloop [(lib,mod):list] db cache w\n\t# (db, cache, w) = getModuleTypes mod lib cache db w\n\t= loop list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[x:c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\/\/ Libraries Library Module\nfindModules` :: ![String] !String !*World -> *(![(String,String)], !*World)\nfindModules` [] _ w = ([], w)\nfindModules` [lib:libs] root w\n#! (mods, w) = findModules lib root w\n#! (moremods, w) = findModules` libs root w\n= (removeDup (mods ++ moremods), w)\n\nfindModules :: !String !String !*World -> *(![(String,String)], !*World)\nfindModules lib root w\n#! (fps, w) = readDirectory (root +++ \"\/\" +++ lib) w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (tuple (root +++ lib)) $ map (\\s->s%(0,size s-5)) $ filter isDclModule fps\n#! (moremods, w) = findModules` (map ((+++) (lib+++\"\/\")) (filter isDirectory fps)) root w\n= (removeDup (mods ++ moremods), w)\nwhere\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String String *DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes mod lib cache db w\n# filename = lib +++ \"\/\" +++ mkdir mod +++ \".dcl\"\n# (ok,f,w) = fopen filename FReadText w\n| not ok = abort (\"Couldn't open file \" +++ filename +++ \".\\n\")\n# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n cache = {cache & hash_table=ht}\n# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" False mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n cache = {cache & hash_table=ht}\n# (ok,w) = fclose f w\n| not ok = abort (\"Couldn't close file \" +++ filename +++ \".\\n\")\n# mod = pm.mod_ident.id_name\n# db = 'DB'.putTypes (pd_typespecs mod pm.mod_defs) db\n# db = 'DB'.putInstancess (pd_instances mod pm.mod_defs) db\n# db = 'DB'.putClasses (pd_classes mod pm.mod_defs) db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = {if (c == '.') '\/' c\\\\c<-:s}\n\n\tpd_typespecs :: String [ParsedDefinition] -> [('DB'.FunctionLocation, 'DB'.ExtendedType)]\n\tpd_typespecs mod pds\n\t\t= [('DB'.FL lib mod id_name, 'DB'.ET ('T'.toType t) {te_priority=toPrio p})\n\t\t \\\\ PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs <- pds]\n\twhere\n\t\ttoPrio :: Priority -> Maybe 'DB'.TE_Priority\n\t\ttoPrio (Prio LeftAssoc i) = Just $ 'DB'.LeftAssoc i\n\t\ttoPrio (Prio RightAssoc i) = Just $ 'DB'.RightAssoc i\n\t\ttoPrio (Prio NoAssoc i) = Just $ 'DB'.NoAssoc i\n\t\ttoPrio _ = Nothing\n\n\tpd_instances :: String [ParsedDefinition] -> [('DB'.Class, ['DB'.Type])]\n\tpd_instances mod pds\n\t\t= [(pi_ident.id_name, map 'T'.toType pi_types)\n\t\t \\\\ PD_Instance {pim_pi={pi_ident,pi_types}} <- pds]\n\n\tpd_classes :: String [ParsedDefinition]\n\t\t-> [('DB'.ClassLocation, ['T'.TypeVar], [('DB'.FunctionName, 'DB'.ExtendedType)])]\n\tpd_classes mod pds\n\t# pds = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) pds\n\t= map (\\(PD_Class {class_ident={id_name},class_args} pds)\n\t\t-> let typespecs = pd_typespecs mod pds\n\t\tin ('DB'.CL lib mod id_name, map 'T'.toTypeVar class_args, \n\t\t\t[(f,et) \\\\ ('DB'.FL _ _ f, et) <- typespecs])) pds\n\nunigroups :: (Type Type -> Bool) [(a,Type)] -> [([a],Type)]\nunigroups f ts = unigroups` ts []\nwhere\n\tunigroups` [] groups = groups\n\tunigroups` [(a,t):ts] [] = unigroups` ts [([a],t)]\n\tunigroups` [(a,t):ts] [(ns,ut):groups]\n\t| f t ut\t= unigroups` ts [([a:ns],ut):groups]\n\t| otherwise = unigroups` ts [(ns,ut):unigroups` [(a,t)] groups]\n\n(<+) infixr 5 :: a b -> [String] | print a & print b\n(<+) a b = print a ++ print b\n\njoin :: a [b] -> [String] | print a & print b\njoin _ [] = []\njoin a [b:[]] = print b\njoin a [b:bs] = b <+ a <+ join a bs\n\nalignl :: Int a -> [String] | print a\nalignl i s\n# s = print s\n# len = sum (map size s)\n| len >= i = s\n| otherwise = s ++ [{' ' \\\\ i <- [0..i-len]}]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"775408a1ca921876efd059fc2c201e3f14386e92","subject":"Changing directory now works (Fixes #2)","message":"Changing directory now works (Fixes #2)\n","repos":"ErinvanderVeen\/Clone,ErinvanderVeen\/Clone","old_file":"src\/Bot.icl","new_file":"src\/Bot.icl","new_contents":"implementation module Bot\n\nimport StdString\nfrom StdMisc import abort\nfrom StdTuple import snd\n\nimport System.Process, Data.Error, System._Posix\nfrom Data.List import isnull\n\nrunBot :: Bot !*World -> (Maybe String, *World)\nrunBot bot world\n# (err, world) = runProcessIO (\".\/\" +++ bot.name) [] (Just \"bots\") world\n| isError err = abort (\"Could not start bot: \" +++ bot.name +++ \"\\n\" +++ snd (fromError err))\n# (handle, io) = fromOk err\n# (err, world) = writePipe (fromMaybe \"\" bot.input) io.stdIn world\n| isError err = abort (\"Could not write to stdIn of \" +++ bot.name +++ \"\\n\" +++ snd (fromError err))\n# (err, world) = closePipe io.stdIn world\n| isError err = abort \"Could not close stdIn pipe\"\n# (err, world) = waitForProcess handle world\n# (result, world) = readStdOut io.stdOut world\n# (err, world) = closePipe io.stdOut world\n| isError err = abort \"Could not close stdOut pipe\"\n| isnull bot.children = (Nothing, world)\n= (result, world)\nwhere\n\treadStdOut :: ReadPipe !*World -> (Maybe String, *World)\n\treadStdOut pipe world\n\t# (err, world) = readPipeNonBlocking pipe world\n\t| isError err = abort \"Could not read stdOut\"\n\t# result = fromOk err\n\t| result == \"\" = (Nothing, world)\n\t= (Just result, world)\n","old_contents":"implementation module Bot\n\nimport StdString\nfrom StdMisc import abort\nfrom StdTuple import snd\n\nimport System.Process, Data.Error, System._Posix\nfrom Data.List import isnull\n\nrunBot :: Bot !*World -> (Maybe String, *World)\nrunBot bot world\n# (err, world) = runProcessIO (\"bots\/\" +++ bot.name) [] (Just \"bots\/\") world\n| isError err = abort (\"Could not start bot: \" +++ bot.name +++ \"\\n\" +++ snd (fromError err))\n# (handle, io) = fromOk err\n# (err, world) = writePipe (fromMaybe \"\" bot.input) io.stdIn world\n| isError err = abort (\"Could not write to stdIn of \" +++ bot.name +++ \"\\n\" +++ snd (fromError err))\n# (err, world) = closePipe io.stdIn world\n| isError err = abort \"Could not close stdIn pipe\"\n# (err, world) = waitForProcess handle world\n# (result, world) = readStdOut io.stdOut world\n# (err, world) = closePipe io.stdOut world\n| isError err = abort \"Could not close stdOut pipe\"\n| isnull bot.children = (Nothing, world)\n= (result, world)\nwhere\n\treadStdOut :: ReadPipe !*World -> (Maybe String, *World)\n\treadStdOut pipe world\n\t# (err, world) = readPipeNonBlocking pipe world\n\t| isError err = abort \"Could not read stdOut\"\n\t# result = fromOk err\n\t| result == \"\" = (Nothing, world)\n\t= (Just result, world)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"4929e9b52b0e92b314d5b03675a52aa25dc3ed85","subject":"Make cache keys more general now that name search is case insensitive","message":"Make cache keys more general now that name search is case insensitive\n","repos":"clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat,toLowerCase), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.name\n\t, c_className = toLowerCase <$> r.className\n\t, c_typeName = toLowerCase <$> r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_include_apps = fromJust (r.include_apps <|> Just DEFAULT_INCLUDE_APPS)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n\/\/#! w = if opts.reload_cache (doInBackground (reloadCache db)) id w\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, CacheKey, !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", \"\", db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond key {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond key (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond key (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond key (err InvalidType \"Couldn't parse type\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond key response db w\n\twhere\n\t\trespond :: !RequestCacheKey !Response !*CloogleDB !*World -> *(!Response, !CacheKey, !*CloogleDB, !*World)\n\t\trespond key r db w = (r, cacheKey key, db, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !CloogleDB -> *World -> *World\n\treloadCache db = uncurry (flip (foldl (flip search))) o allCacheKeys LongTerm\n\twhere\n\t\tsearch :: !RequestCacheKey -> *World -> *World\n\t\tsearch r = thd3 o handle db (Just $ fromRequestCacheKey r) o removeFromCache LongTerm r\n\n\tdoInBackground :: (*World -> *World) *World -> *World\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_include_apps = fromJust (r.include_apps <|> Just DEFAULT_INCLUDE_APPS)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n\/\/#! w = if opts.reload_cache (doInBackground (reloadCache db)) id w\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, CacheKey, !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", \"\", db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond key {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond key (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond key (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond key (err InvalidType \"Couldn't parse type\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond key response db w\n\twhere\n\t\trespond :: !RequestCacheKey !Response !*CloogleDB !*World -> *(!Response, !CacheKey, !*CloogleDB, !*World)\n\t\trespond key r db w = (r, cacheKey key, db, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !CloogleDB -> *World -> *World\n\treloadCache db = uncurry (flip (foldl (flip search))) o allCacheKeys LongTerm\n\twhere\n\t\tsearch :: !RequestCacheKey -> *World -> *World\n\t\tsearch r = thd3 o handle db (Just $ fromRequestCacheKey r) o removeFromCache LongTerm r\n\n\tdoInBackground :: (*World -> *World) *World -> *World\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"b27eb374af890c6fc60ef43b26ac2aad06d8ee16","subject":"Add shorthand record update in # to syntax","message":"Add shorthand record update in # to syntax\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/Builtins.icl","new_file":"backend\/Builtins.icl","new_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [(Location, FunctionEntry)]\nbuiltin_functions\n\t= [ ( Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , {zero & fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []}\n\t )\n\t , ( Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , {zero & fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]}\n\t )\n\t ]\n\nbuiltin_classes :: [(Location, ClassEntry)]\nbuiltin_classes\n\t= [ ( Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , { ce_vars=[\"v\"]\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t }\n\t )\n\t ]\n\nbuiltin_types :: [(Location, TypeDefEntry)]\nbuiltin_types\n\t= [ ( Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , { deft\n\t & tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Int\"})\n\t , ( Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Real\"})\n\t , ( Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Char\"})\n\t , ( Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"String\",\n\t tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], {deft & tde_typedef.td_name = \"Dynamic\"})\n\t , ( Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"File\"})\n\t , ( Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"World\",\n\t tde_typedef.td_uniq = True,\n\t tde_doc = Just $ TypeDoc\n\t (Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\")\n\t [] Nothing})\n\t , ( Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"], {deft & tde_typedef.td_name = \"(->)\",\n\t tde_typedef.td_args = [Var \"a\", Var \"b\"],\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\")\n\t [\"The argument type\", \"The result type\"]\n\t Nothing})\n\t : lists\n\t ++ arrays\n\t ++ tuples\n\t ]\nwhere\n\tdeft = {tde_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract}, tde_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> (Location, TypeDefEntry)\n\t\tmake_list k s = (Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description)\n\t\t\t\t[\"The type of the list elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> (Location, TypeDefEntry)\n\t\tmake_array k = (Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description)\n\t\t\t\t[\"The type of the array elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> (Location, TypeDefEntry)\n\t\tmake_tuple n = (Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t \"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t \"Clean supports tuples of arity 2 to 32.\")\n\t\t\t\t[] Nothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_class = ([\"class\"],\n\t{ syntax_title = \"class\"\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t})\n\nbs_code = ([\"code\", \"inline\", \"code inline\"],\n\t{ syntax_title = \"ABC code\"\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t})\n\nbs_generic = ([\"generic\", \"derive\", \"of\", \"{|*|}\"], \/\/ This * matches everything, which is intentional\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_instance = ([\"instance\"],\n\t{ syntax_title = \"instance\"\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t})\n\nbs_lambda = ([\"lambda\", \"\\\\*\", \"->\", \".\"],\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t})\n\nbs_layout_rule = ([\";\", \"{\", \"}\"],\n\t{ syntax_title = \"layout rule\"\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_list_expressions = ([\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"],\n\t{ syntax_title = \"list expression\"\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t})\n\nbs_macro = ([\":==\", \"macro\"],\n\t{ syntax_title = \"macro\"\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t})\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t})\n\nbs_selection_array = ([\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"],\n\t{ syntax_title = \"array selection\"\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t})\nbs_selection_array_unique = ([\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"],\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t})\nbs_selection_record = ([\".\"],\n\t{ syntax_title = \"record selection\"\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t})\nbs_selection_record_unique = ([\"!\"],\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n\nbs_zf = ([\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"],\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t})\n","old_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [(Location, FunctionEntry)]\nbuiltin_functions\n\t= [ ( Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , {zero & fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []}\n\t )\n\t , ( Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , {zero & fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]}\n\t )\n\t ]\n\nbuiltin_classes :: [(Location, ClassEntry)]\nbuiltin_classes\n\t= [ ( Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , { ce_vars=[\"v\"]\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t }\n\t )\n\t ]\n\nbuiltin_types :: [(Location, TypeDefEntry)]\nbuiltin_types\n\t= [ ( Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , { deft\n\t & tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Int\"})\n\t , ( Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Real\"})\n\t , ( Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Char\"})\n\t , ( Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"String\",\n\t tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], {deft & tde_typedef.td_name = \"Dynamic\"})\n\t , ( Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"File\"})\n\t , ( Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"World\",\n\t tde_typedef.td_uniq = True,\n\t tde_doc = Just $ TypeDoc\n\t (Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\")\n\t [] Nothing})\n\t , ( Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"], {deft & tde_typedef.td_name = \"(->)\",\n\t tde_typedef.td_args = [Var \"a\", Var \"b\"],\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\")\n\t [\"The argument type\", \"The result type\"]\n\t Nothing})\n\t : lists\n\t ++ arrays\n\t ++ tuples\n\t ]\nwhere\n\tdeft = {tde_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract}, tde_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> (Location, TypeDefEntry)\n\t\tmake_list k s = (Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description)\n\t\t\t\t[\"The type of the list elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> (Location, TypeDefEntry)\n\t\tmake_array k = (Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description)\n\t\t\t\t[\"The type of the array elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> (Location, TypeDefEntry)\n\t\tmake_tuple n = (Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t \"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t \"Clean supports tuples of arity 2 to 32.\")\n\t\t\t\t[] Nothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_class = ([\"class\"],\n\t{ syntax_title = \"class\"\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t})\n\nbs_code = ([\"code\", \"inline\", \"code inline\"],\n\t{ syntax_title = \"ABC code\"\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t})\n\nbs_generic = ([\"generic\", \"derive\", \"of\", \"{|*|}\"], \/\/ This * matches everything, which is intentional\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_instance = ([\"instance\"],\n\t{ syntax_title = \"instance\"\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t})\n\nbs_lambda = ([\"lambda\", \"\\\\*\", \"->\", \".\"],\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t})\n\nbs_layout_rule = ([\";\", \"{\", \"}\"],\n\t{ syntax_title = \"layout rule\"\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_list_expressions = ([\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"],\n\t{ syntax_title = \"list expression\"\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t})\n\nbs_macro = ([\":==\", \"macro\"],\n\t{ syntax_title = \"macro\"\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t})\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t})\n\nbs_selection_array = ([\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"],\n\t{ syntax_title = \"array selection\"\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t})\nbs_selection_array_unique = ([\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"],\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t})\nbs_selection_record = ([\".\"],\n\t{ syntax_title = \"record selection\"\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t})\nbs_selection_record_unique = ([\"!\"],\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code = [\"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code = [\"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n\nbs_zf = ([\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"],\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t})\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"55f366293cdef6d931d77513cbbecdb3a465dbec","subject":"Add syntax example for zf with array assignment","message":"Add syntax example for zf with array assignment\n","repos":"clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\"]\n\t, syntax_code = [\"*...\"]\n\t, syntax_description = \"Annotates a type to be unique.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i\\\\i<-[0,2..9] } \/\/ Fancy things can be done if you combine this with a {{ZF}}. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\"]\n\t, syntax_code = [\"*...\"]\n\t, syntax_description = \"Annotates a type to be unique.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"e6122274015bff5500347501470c2071a515451d","subject":"Cleanup","message":"Cleanup\n","repos":"clean-cloogle\/clean-irc","old_file":"IRC.icl","new_file":"IRC.icl","new_contents":"implementation module IRC\n\nimport StdList, StdTuple, StdOverloaded, StdFunc, StdString, StdChar, StdBool\nimport GenPrint\nimport Data.Maybe\nimport Data.Either\nimport _SystemArray\n\nimport Text.Parsers.Simple.Core\nimport Text.Parsers.Simple.Chars\nimport Data.Tuple\nimport Control.Monad\nimport Control.Applicative\n\nfrom Data.Functor import <$>\nfrom Data.Func import $\nfrom Text import class Text(trim,rtrim,split,indexOf,concat), instance Text String\nimport qualified Text\nfrom StdMisc import undef\n\njon :== 'Text'.join\n\nderive gPrint IRCCommand, IRCReplies, IRCErrors, (,), Maybe, (), Either, IRCMessage, IRCUser, IRCNumReply\n\nStart = jon \"\\n\" $ map printToString\n\t[ parseIRCMessage \":clooglebot!~cloogle@dhcp-077-249-221-037.chello.nl QUIT\\r\\n\"\n\t, parseIRCMessage \":clooglebot!~cloogle QUIT\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 QUIT\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY test\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY :test with spaces\\r\\n\"\n\t, parseIRCMessage \":cherryh.freenode.net NOTICE * :*** Found your hostname\\r\\n\"\n\t, parseIRCMessage \":cherryh.freenode.net QUIT :hoi hoi\\r\\n\"\n\t, parseIRCMessage \":cherryh.freenode.net ISON a b c d e f :g h\\r\\n\"\n\t]\n\n(<+) infixr 5 :: a b -> String | toString a & toString b\n(<+) a b = toString a +++ toString b\n\nparseIRCMessage :: String -> Either [Error] IRCMessage\nparseIRCMessage s = case runParser parsePrefix (fromString s) of\n\t([(prefix, rest):_], _)\n\t\t= case parse parseReply rest of\n\t\t\tLeft e = case parseCmd rest of\n\t\t\t\tLeft e2 = Left $ e2 ++ e\n\t\t\t\tRight cmd = Right {IRCMessage | irc_prefix=prefix, irc_command=Right cmd}\n\t\t\tRight repl = Right {IRCMessage | irc_prefix=prefix, irc_command=Left repl}\n\t(_, es) = Left [\"couldn't parse prefix\":es]\n\nparsePrefix :: Parser Char (Maybe (Either IRCUser String))\nparsePrefix = optional (pToken ':' >>| parseEither parseUser parseHost) <* pToken ' '\n\npOne [] = (Left [\"Expected an argument\"], [])\npOne [a:as] = (Right a, as)\n\ngeneric gIRCParse a :: [String] -> (Either [Error] a, [String])\ngIRCParse{|UNIT|} a = (Right UNIT, a)\ngIRCParse{|String|} as = pOne as\ngIRCParse{|Int|} as = appFst (fmap toInt) $ pOne as\ngIRCParse{|EITHER|} lp rp as = case lp as of\n\t(Right a, rest) = (Right $ LEFT a, rest)\n\t(Left e1, _) = case rp as of\n\t\t(Right a, rest) = (Right $ RIGHT a, rest)\n\t\t(Left e2, _) = (Left $ e1 ++ e2, [])\ngIRCParse{|OBJECT|} p as = appFst (fmap OBJECT) $ p as\ngIRCParse{|CONS of d|} p [] = (Left [\"Expected a cmd constructor: \" +++ d.gcd_name], [])\ngIRCParse{|CONS of d|} p [a:as]\n| a <> d.gcd_name = (Left [\"Wrong constructor. expected: \" +++ d.gcd_name +++ \", got: \" +++ a], [])\n= case p as of\n\t(Right a, rest) = (Right $ CONS a, rest)\n\t(Left e, _) = (Left e, [])\ngIRCParse{|PAIR|} pl pr as = case pl as of\n\t(Right a1, rest) = case pr rest of\n\t\t(Right a2, rest) = (Right $ PAIR a1 a2, rest)\n\t\t(Left e, _) = (Left e, [])\n\t(Left e, _) = (Left e, [])\ngIRCParse{|[]|} pl as = case pl as of\n\t\t(Right e, rest) = case gIRCParse{|*->*|} pl rest of\n\t\t\t(Right es, rest) = (Right [e:es], rest)\n\t\t\t(Left e, _) = (Left e, [])\n\t\t(Left e, _) = (Right [], as)\ngIRCParse{|Maybe|} pm as\n\t= appFst (either (const $ Right Nothing) $ Right o Just) $ pm as\n\nderive gIRCParse (,), (,,), IRCCommand\n\nparseCmd :: [Char] -> Either [Error] IRCCommand\nparseCmd cs = fst $ gIRCParse{|*|} $ argfun $ split \" \" $ toString cs\n\twhere\n\t\targfun :: [String] -> [String]\n\t\targfun [] = []\n\t\targfun [x:xs]\n\t\t# x = trim x\n\t\t| x.[0] == ':' = [jon \" \" $ [x:map rtrim xs]]\n\t\t| otherwise = [x:argfun xs]\n\nparseReply :: Parser Char IRCNumReply\nparseReply = (toString <$> pSome pDigit)\n\t>>= \\rep->pMiddle\n\t>>= \\recipient->spaceParser >>| (toString <$> pSome (pNoneOf illegal))\n\t>>= \\msg->pure {IRCNumReply|irc_reply=fs rep,irc_recipient=recipient,irc_message=msg}\n\twhere\n\t\tfs :: String -> IRCReplies\n\t\tfs s = fromInt $ toInt s\n\/\/\nspaceParser :: Parser Char [Char]\nspaceParser = pMany $ pToken ' '\n\/\/\n\/\/parseServer :: Parser Char String\n\/\/parseServer = pFail\n\/\/\nparseEither :: (Parser a b) (Parser a c) -> Parser a (Either b c)\nparseEither p q = Left <$> p <|> Right <$> q\n\nparseUser :: Parser Char IRCUser\nparseUser = parseNick\n\t\t>>= \\nick->optional (pToken '!' >>| parseUsr)\n\t\t>>= \\muser->optional (pToken '@' >>| parseHost)\n\t\t>>= \\mhost->pure {IRCUser | irc_nick=nick, irc_user=muser, irc_host=mhost}\n\nparseUsr :: Parser Char String\nparseUsr = toString <$> pSome (pNoneOf [' ', '@':illegal])\n\nparseNick :: Parser Char String\nparseNick = pAlpha >>= \\c->pMany (pAlpha <|> pDigit <|> pSpecial)\n\t>>= \\cs->pure (toString [c:cs])\n\npSpecial :: Parser Char Char\npSpecial = pOneOf ['-', '[', ']', '\\\\', '\\`', '^', '{', '}']\n\nparseHost :: Parser Char String\nparseHost = jon \".\" <$> pSepBy parseName (pToken '.')\n\twhere\n\t\tparseName :: Parser Char String\n\t\tparseName = toString <$> pSome (pAlpha <|> pDigit <|> pOneOf ['-'])\n\ninstance toString IRCNumReply where\n\ttoString m = toInt m.irc_reply <+ \" \" <+ m.irc_recipient <+ \" \" <+ formatMSG m.irc_message\ninstance toString IRCMessage where\n\ttoString m = maybe \"\" (\\s->either ((<+) \":\") id s <+ \" \") m.irc_prefix\n\t\t<+ either toString toString m.irc_command\n\ninstance toString IRCUser where\n\ttoString m = m.irc_nick <+ maybe \"\" ((<+) \"!\") m.irc_user\n\t\t<+ maybe \"\" ((<+) \"@\") m.irc_host\n\npMiddle :: Parser Char String\npMiddle = fmap toString $\n\tspaceParser >>| liftM2 (\\x xs->[x:xs]) (pSatisfy (not o ((==)':')) (pMany $ pNoneOf [' ':illegal]))\n\npNoneOf :: [a] -> Parser a a | Eq a\npNoneOf l = pSatisfy (not o flip isMember l)\n\nillegal :: [Char]\nillegal = ['\\x00','\\r','\\n']\n\ninstance toString IRCCommand where\n\ttoString r = jon \" \" (gIRCPrint{|*|} r) +++ \"\\r\\n\"\n\nformatMSG :: String -> String\nformatMSG s = if (indexOf \" \" s > 0 || indexOf \" \" s > 0) (\":\" +++ s) s\n\ninstance toString IRCReplies where toString r = printToString r\ninstance toString IRCErrors where toString r = printToString r\n\ninstance fromInt IRCReplies where\n\tfromInt r = case r of \n\t\t1 = RPL_WELCOME; 2 = RPL_YOURHOST;\n\t\t3 = RPL_CREATED; 4 = RPL_MYINFO;\n\t\t5 = RPL_BOUNCE; 200 = RPL_TRACELINK;\n\t\t201 = RPL_TRACECONNECTING; 202 = RPL_TRACEHANDSHAKE;\n\t\t203 = RPL_TRACEUNKNOWN; 204 = RPL_TRACEOPERATOR;\n\t\t205 = RPL_TRACEUSER; 206 = RPL_TRACESERVER;\n\t\t207 = RPL_TRACESERVICE; 208 = RPL_TRACENEWTYPE;\n\t\t209 = RPL_TRACECLASS; 210 = RPL_TRACERECONNECT;\n\t\t211 = RPL_STATSLINKINFO; 212 = RPL_STATSCOMMANDS;\n\t\t219 = RPL_ENDOFSTATS; 221 = RPL_UMODEIS;\n\t\t234 = RPL_SERVLIST; 235 = RPL_SERVLISTEND;\n\t\t242 = RPL_STATSUPTIME; 243 = RPL_STATSOLINE;\n\t\t251 = RPL_LUSERCLIENT; 252 = RPL_LUSEROP;\n\t\t253 = RPL_LUSERUNKNOWN; 254 = RPL_LUSERCHANNELS;\n\t\t255 = RPL_LUSERME; 256 = RPL_ADMINME;\n\t\t257 = RPL_ADMINLOC1; 258 = RPL_ADMINLOC2;\n\t\t259 = RPL_ADMINEMAIL; 261 = RPL_TRACELOG;\n\t\t262 = RPL_TRACEEND; 263 = RPL_TRYAGAIN;\n\t\t301 = RPL_AWAY; 302 = RPL_USERHOST;\n\t\t303 = RPL_ISON; 304 = RPL_UNAWAY;\n\t\t305 = RPL_NOWAWAY; 311 = RPL_WHOISUSER;\n\t\t312 = RPL_WHOISSERVER; 313 = RPL_WHOISOPERATOR;\n\t\t314 = RPL_WHOWASUSER; 315 = RPL_ENDOFWHO;\n\t\t317 = RPL_WHOISIDLE; 318 = RPL_ENDOFWHOIS;\n\t\t319 = RPL_WHOISCHANNELS; 321 = RPL_LISTSTART;\n\t\t322 = RPL_LIST; 323 = RPL_LISTEND;\n\t\t324 = RPL_CHANNELMODEIS; 325 = RPL_UNIQOPIS;\n\t\t331 = RPL_NOTOPIC; 332 = RPL_TOPIC;\n\t\t341 = RPL_INVITING; 342 = RPL_SUMMONING;\n\t\t346 = RPL_INVITELIST; 347 = RPL_ENDOFINVITELIST;\n\t\t348 = RPL_EXCEPTLIST; 349 = RPL_ENDOFEXCEPTLIST;\n\t\t351 = RPL_VERSION; 352 = RPL_WHOREPLY;\n\t\t353 = RPL_NAMREPLY; 364 = RPL_LINKS;\n\t\t365 = RPL_ENDOFLINKS; 366 = RPL_ENDOFNAMES;\n\t\t367 = RPL_BANLIST; 368 = RPL_ENDOFBANLIST;\n\t\t369 = RPL_ENDOFWHOWAS; 371 = RPL_INFO;\n\t\t372 = RPL_MOTD; 374 = RPL_ENDOFINFO;\n\t\t375 = RPL_MOTDSTART; 376 = RPL_ENDOFMOTD;\n\t\t381 = RPL_YOUREOPER; 382 = RPL_REHASHING;\n\t\t383 = RPL_YOURESERVICE; 391 = RPL_TIME;\n\t\t392 = RPL_USERSSTART; 393 = RPL_USERS;\n\t\t394 = RPL_ENDOFUSERS; 395 = RPL_NOUSERS;\n\t\t_ = undef\n\ninstance toInt IRCReplies where\n\ttoInt r = case r of \n\t\tRPL_WELCOME = 1; RPL_YOURHOST = 2;\n\t\tRPL_CREATED = 3; RPL_MYINFO = 4;\n\t\tRPL_BOUNCE = 5; RPL_TRACELINK = 200;\n\t\tRPL_TRACECONNECTING = 201; RPL_TRACEHANDSHAKE = 202;\n\t\tRPL_TRACEUNKNOWN = 203; RPL_TRACEOPERATOR = 204;\n\t\tRPL_TRACEUSER = 205; RPL_TRACESERVER = 206;\n\t\tRPL_TRACESERVICE = 207; RPL_TRACENEWTYPE = 208;\n\t\tRPL_TRACECLASS = 209; RPL_TRACERECONNECT = 210;\n\t\tRPL_STATSLINKINFO = 211; RPL_STATSCOMMANDS = 212;\n\t\tRPL_ENDOFSTATS = 219; RPL_UMODEIS = 221;\n\t\tRPL_SERVLIST = 234; RPL_SERVLISTEND = 234;\n\t\tRPL_STATSUPTIME = 242; RPL_STATSOLINE = 243;\n\t\tRPL_LUSERCLIENT = 251; RPL_LUSEROP = 252;\n\t\tRPL_LUSERUNKNOWN = 253; RPL_LUSERCHANNELS = 254;\n\t\tRPL_LUSERME = 255; RPL_ADMINME = 256;\n\t\tRPL_ADMINLOC1 = 257; RPL_ADMINLOC2 = 258;\n\t\tRPL_ADMINEMAIL = 259; RPL_TRACELOG = 261;\n\t\tRPL_TRACEEND = 262; RPL_TRYAGAIN = 263;\n\t\tRPL_AWAY = 301; RPL_USERHOST = 302;\n\t\tRPL_ISON = 303; RPL_UNAWAY = 304;\n\t\tRPL_NOWAWAY = 305; RPL_WHOISUSER = 311;\n\t\tRPL_WHOISSERVER = 312; RPL_WHOISOPERATOR = 313;\n\t\tRPL_WHOWASUSER = 314; RPL_ENDOFWHO = 315;\n\t\tRPL_WHOISIDLE = 317; RPL_ENDOFWHOIS = 318;\n\t\tRPL_WHOISCHANNELS = 319; RPL_LISTSTART = 321;\n\t\tRPL_LIST = 322; RPL_LISTEND = 323;\n\t\tRPL_CHANNELMODEIS = 324; RPL_UNIQOPIS = 325;\n\t\tRPL_NOTOPIC = 331; RPL_TOPIC = 332;\n\t\tRPL_INVITING = 341; RPL_SUMMONING = 342;\n\t\tRPL_INVITELIST = 346; RPL_ENDOFINVITELIST = 347;\n\t\tRPL_EXCEPTLIST = 348; RPL_ENDOFEXCEPTLIST = 349;\n\t\tRPL_VERSION = 351; RPL_WHOREPLY = 352;\n\t\tRPL_NAMREPLY = 353; RPL_LINKS = 364;\n\t\tRPL_ENDOFLINKS = 365; RPL_ENDOFNAMES = 366;\n\t\tRPL_BANLIST = 367; RPL_ENDOFBANLIST = 367;\n\t\tRPL_ENDOFWHOWAS = 369; RPL_INFO = 371;\n\t\tRPL_MOTD = 372; RPL_ENDOFINFO = 374;\n\t\tRPL_MOTDSTART = 375; RPL_ENDOFMOTD = 376;\n\t\tRPL_YOUREOPER = 381; RPL_REHASHING = 382;\n\t\tRPL_YOURESERVICE = 383; RPL_TIME = 391;\n\t\tRPL_USERSSTART = 392; RPL_USERS = 393;\n\t\tRPL_ENDOFUSERS = 394; RPL_NOUSERS = 395;\n\ninstance fromInt IRCErrors where\n\tfromInt r = case r of\n\t\t401 = ERR_NOSUCHNICK; 402 = ERR_NOSUCHSERVER;\n\t\t403 = ERR_NOSUCHCHANNEL; 404 = ERR_CANNOTSENDTOCHAN;\n\t\t405 = ERR_TOOMANYCHANNELS; 406 = ERR_WASNOSUCHNICK;\n\t\t407 = ERR_TOOMANYTARGETS; 408 = ERR_NOSUCHSERVICE;\n\t\t409 = ERR_NOORIGIN; 411 = ERR_NORECIPIENT;\n\t\t412 = ERR_NOTEXTTOSEND; 413 = ERR_NOTOPLEVEL;\n\t\t414 = ERR_WILDTOPLEVEL; 415 = ERR_BADMASK;\n\t\t421 = ERR_UNKNOWNCOMMAND; 422 = ERR_NOMOTD;\n\t\t423 = ERR_NOADMININFO; 424 = ERR_FILEERROR;\n\t\t431 = ERR_NONICKNAMEGIVEN; 432 = ERR_ERRONEUSNICKNAME;\n\t\t433 = ERR_NICKNAMEINUSE; 436 = ERR_NICKCOLLISION;\n\t\t437 = ERR_UNAVAILRESOURCE; 441 = ERR_USERNOTINCHANNEL;\n\t\t442 = ERR_NOTONCHANNEL; 443 = ERR_USERONCHANNEL;\n\t\t444 = ERR_NOLOGIN; 445 = ERR_SUMMONDISABLED;\n\t\t446 = ERR_USERSDISABLED; 451 = ERR_NOTREGISTERED;\n\t\t461 = ERR_NEEDMOREPARAMS; 462 = ERR_ALREADYREGISTRED;\n\t\t463 = ERR_NOPERMFORHOST; 464 = ERR_PASSWDMISMATCH;\n\t\t465 = ERR_YOUREBANNEDCREEP; 466 = ERR_YOUWILLBEBANNED;\n\t\t467 = ERR_KEYSET; 471 = ERR_CHANNELISFULL;\n\t\t472 = ERR_UNKNOWNMODE; 473 = ERR_INVITEONLYCHAN;\n\t\t474 = ERR_BANNEDFROMCHAN; 475 = ERR_BADCHANNELKEY;\n\t\t476 = ERR_BADCHANMASK; 477 = ERR_NOCHANMODES;\n\t\t478 = ERR_BANLISTFULL; 481 = ERR_NOPRIVILEGES;\n\t\t482 = ERR_CHANOPRIVSNEEDED; 483 = ERR_CANTKILLSERVER;\n\t\t484 = ERR_RESTRICTED; 485 = ERR_UNIQOPPRIVSNEEDED;\n\t\t491 = ERR_NOOPERHOST; 501 = ERR_UMODEUNKNOWNFLAG;\n\t\t502 = ERR_USERSDONTMATCH;\n\ninstance toInt IRCErrors where\n\ttoInt r = case r of\n\t\tERR_NOSUCHNICK = 401; ERR_NOSUCHSERVER = 402;\n\t\tERR_NOSUCHCHANNEL = 403; ERR_CANNOTSENDTOCHAN = 404;\n\t\tERR_TOOMANYCHANNELS = 405; ERR_WASNOSUCHNICK = 406;\n\t\tERR_TOOMANYTARGETS = 407; ERR_NOSUCHSERVICE = 408;\n\t\tERR_NOORIGIN = 409; ERR_NORECIPIENT = 411;\n\t\tERR_NOTEXTTOSEND = 412; ERR_NOTOPLEVEL = 413;\n\t\tERR_WILDTOPLEVEL = 414; ERR_BADMASK = 415;\n\t\tERR_UNKNOWNCOMMAND = 421; ERR_NOMOTD = 422;\n\t\tERR_NOADMININFO = 423; ERR_FILEERROR = 424;\n\t\tERR_NONICKNAMEGIVEN = 431; ERR_ERRONEUSNICKNAME = 432;\n\t\tERR_NICKNAMEINUSE = 433; ERR_NICKCOLLISION = 436;\n\t\tERR_UNAVAILRESOURCE = 437; ERR_USERNOTINCHANNEL = 441;\n\t\tERR_NOTONCHANNEL = 442; ERR_USERONCHANNEL = 443;\n\t\tERR_NOLOGIN = 444; ERR_SUMMONDISABLED = 445;\n\t\tERR_USERSDISABLED = 446; ERR_NOTREGISTERED = 451;\n\t\tERR_NEEDMOREPARAMS = 461; ERR_ALREADYREGISTRED = 462;\n\t\tERR_NOPERMFORHOST = 463; ERR_PASSWDMISMATCH = 464;\n\t\tERR_YOUREBANNEDCREEP = 465; ERR_YOUWILLBEBANNED = 466;\n\t\tERR_KEYSET = 467; ERR_CHANNELISFULL = 471;\n\t\tERR_UNKNOWNMODE = 472; ERR_INVITEONLYCHAN = 473;\n\t\tERR_BANNEDFROMCHAN = 474; ERR_BADCHANNELKEY = 475;\n\t\tERR_BADCHANMASK = 476; ERR_NOCHANMODES = 477;\n\t\tERR_BANLISTFULL = 478; ERR_NOPRIVILEGES = 481;\n\t\tERR_CHANOPRIVSNEEDED = 482; ERR_CANTKILLSERVER = 483;\n\t\tERR_RESTRICTED = 484; ERR_UNIQOPPRIVSNEEDED = 485;\n\t\tERR_NOOPERHOST = 491; ERR_UMODEUNKNOWNFLAG = 501;\n\t\tERR_USERSDONTMATCH = 502;\n","old_contents":"implementation module IRC\n\nimport StdGeneric\nimport StdList\nimport StdTuple\nimport GenPrint\nimport GenBimap\nimport StdOverloaded\nimport Data.Maybe\nimport Data.Either\nimport StdFunc\nimport StdString\nimport StdChar\nimport StdBool\nimport _SystemArray\n\nimport Text.Parsers.Simple.Core\nimport Text.Parsers.Simple.Chars\nimport Data.Tuple\nimport Control.Monad\nimport Control.Applicative\nfrom Data.Functor import <$>\n\nfrom Data.Func import $\nfrom Text import class Text(ltrim,indexOf,concat), instance Text String\nimport qualified Text\nfrom StdMisc import undef\nimport StdDebug\n\njon :== 'Text'.join\n\nderive gPrint IRCCommand, IRCReplies, IRCErrors, (,), Maybe, (), Either, IRCMessage, IRCUser, IRCNumReply\n\nStart = jon \"\\n\" $ map printToString\n\t[ parseIRCMessage \":clooglebot!~cloogle@dhcp-077-249-221-037.chello.nl QUIT\\r\\n\"\n\t, parseIRCMessage \":clooglebot!~cloogle QUIT\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 QUIT\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY test\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY :test with spaces\\r\\n\"\n\t, parseIRCMessage \":cherryh.freenode.net NOTICE * :*** Found your hostname\\r\\n\"\n\t, parseIRCMessage \":cherryh.freenode.net QUIT :hoi hoi\\r\\n\"\n\t]\n\n(<+) infixr 5 :: a b -> String | toString a & toString b\n(<+) a b = toString a +++ toString b\n\nparseIRCMessage :: String -> Either [Error] IRCMessage\nparseIRCMessage s = case runParser parsePrefix (fromString s) of\n\t([(prefix, rest):_], _)\n\t\t= case parse parseReply rest of\n\t\t\tLeft e = case parseCmd rest of\n\t\t\t\tLeft e2 = Left $ e2 ++ e\n\t\t\t\tRight cmd = Right {IRCMessage | irc_prefix=prefix, irc_command=Right cmd}\n\t\t\tRight repl = Right {IRCMessage | irc_prefix=prefix, irc_command=Left repl}\n\t(_, es) = Left [\"couldn't parse prefix\":es]\n\nparsePrefix :: Parser Char (Maybe (Either IRCUser String))\nparsePrefix = optional (pToken ':' >>| parseEither parseUser parseHost) <* pToken ' '\n\ngeneric gIRCParse a :: [String] -> (Either [Error] a, [String])\ngIRCParse{|UNIT|} a = (Right UNIT, a)\ngIRCParse{|String|} [a:as] = (Right a, as)\ngIRCParse{|String|} [] = (Left [\"Expected a string\"], [])\ngIRCParse{|Int|} [a:as] = (Right $ toInt a, as)\ngIRCParse{|Int|} [] = (Left [\"Expected an integer\"], [])\ngIRCParse{|EITHER|} lp rp as = case lp as of\n\t(Right a, rest) = (Right $ LEFT a, rest)\n\t(Left e1, rest) = case rp as of\n\t\t(Right a, rest) = (Right $ RIGHT a, rest)\n\t\t(Left e2, rest) = (Left $ e1 ++ e2, [])\ngIRCParse{|OBJECT|} p as = case p as of\n\t(Right e, rest) = (Right $ OBJECT e, rest)\n\t(Left e, rest) = (Left e, [])\ngIRCParse{|CONS of d|} p [] = (Left [\"Expected a cmd constructor: \" +++ d.gcd_name], [])\ngIRCParse{|CONS of d|} p [a:as]\n| a <> d.gcd_name = (Left [\"Wrong constructor. expected: \" +++ d.gcd_name +++ \", got: \" +++ a], [])\n= case p as of\n\t(Right a, rest) = (Right $ CONS a, rest)\n\t(Left e, rest) = (Left e, [])\ngIRCParse{|PAIR|} pl pr as = case pl as of\n\t(Right a1, rest) = case pr rest of\n\t\t(Right a2, rest) = (Right $ PAIR a1 a2, rest)\n\t\t(Left e, rest) = (Left e, [])\n\t(Left e, rest) = (Left e, [])\ngIRCParse{|[]|} pl as = plist pl as\nwhere\n\tplist pl as = case pl as of\n\t\t(Right e, rest) = case plist pl rest of\n\t\t\t(Right es, rest) = (Right [e:es], rest)\n\t\t\t(Left e, rest) = (Left e, [])\n\t\t(Left e, rest) = (Right [], as)\ngIRCParse{|Maybe|} pm as = case pm as of\n\t(Right a, rest) = (Right $ Just a, rest)\n\t(Left e, rest) = (Right Nothing, as)\n\nderive gIRCParse (,), (,,), IRCCommand\n\nparseCmd :: [Char] -> Either [Error] IRCCommand\nparseCmd cs = fst $ gIRCParse{|*|} $ argfun $ 'Text'.split \" \" $ toString cs\n\/\/= parse cmdParser $ argfun $ 'Text'.split \" \" $ toString cs\n\twhere\n\t\targfun :: [String] -> [String]\n\t\targfun [] = []\n\t\targfun [x:xs]\n\t\t# x = 'Text'.trim x\n\t\t| x.[0] == ':' = [jon \" \" $ [x:map 'Text'.rtrim xs]]\n\t\t| otherwise = [x:argfun xs]\n\n\t\tp = pSatisfy (const True)\n\t\tlst = fmap $ 'Text'.split \",\"\n\t\topt = optional p\n\t\tpInt = toInt <$> p\n\n\t\tnn p f = pToken p >>| f\n\n\t\tcmdParser :: Parser String IRCCommand\n\t\tcmdParser =\n\t\t\t (nn \"ADMIN\" $ fmap ADMIN opt)\n\t\t\t<|> (nn \"AWAY\" $ fmap AWAY p)\n\t\t\t<|> (nn \"CONNECT\" $ liftM2 CONNECT p (optional $ liftM2 tuple pInt opt))\n\t\t\t<|> (nn \"DIE\" $ pure DIE)\n\t\t\t<|> (nn \"ERROR\" $ fmap ERROR p)\n\t\t\t<|> (nn \"INFO\" $ fmap INFO opt)\n\t\t\t<|> (nn \"INVITE\" $ liftM2 INVITE p p)\n\t\t\t<|> (nn \"ISON\" $ fmap ISON $ pMany p)\n\/\/\t\t\t<|> (nn \"JOIN\" $ fmap JOIN $ lst p >>= \\ch->lst p >>= \\ks->pure (zip2 ch (ks ++ repeat Nothing)))\n\t\t\t<|> (nn \"KICK\" $ liftM3 KICK p p opt)\n\t\t\t<|> (nn \"KILL\" $ liftM2 KILL p p)\n\t\t\t<|> (nn \"LINKS\" $ fmap LINKS $ optional $ liftM2 tuple opt p)\n\t\t\t<|> (nn \"LIST\" $ fmap LIST $ optional $ liftM2 tuple ('Text'.split \",\" <$> p) opt)\n\t\t\t<|> (nn \"LUSERS\" $ fmap LUSERS $ optional $ liftM2 tuple p opt)\n\t\t\t<|> (nn \"MODE\" $ liftM5 MODE p p opt opt opt)\n\t\t\t<|> (nn \"MOTD\" $ fmap MOTD $ opt)\n\t\t\t<|> (nn \"NAMES\" $ fmap NAMES $ lst p)\n\t\t\t<|> (nn \"NICK\" $ fmap NAMES $ lst p)\n\t\t\t\/\/\"NICK\" = String (Maybe String)\n\t\t\t\/\/\"NJOIN\" = command0 NJOIN args\n\t\t\t\/\/\"NOTICE\" = String String\n\t\t\t\/\/\"OPER\" = String String \n\t\t\t\/\/\"PART\" = [String]\n\t\t\t\/\/\"PASS\" = String\n\t\t\t\/\/\"PING\" = String (Maybe String)\n\t\t\t\/\/\"PONG\" = String (Maybe String)\n\t\t\t\/\/\"PRIVMSG\" = [String] String\n\/\/\t\t\t\"QUIT\" = case args of\n\/\/\t\t\t\t[_,_:_] = Left $ \"QUIT has too many arguments\"\n\/\/\t\t\t\tx = Right $ QUIT $ listToMaybe x\n\/\/\t\t\t\"REHASH\" = command0 REHASH args\n\/\/\t\t\t\"RESTART\" = command0 REHASH args\n\/\/\t\t\t\"SERVER\" = command0 REHASH args\n\t\t\t\/\/\"SERVICE\" = String String String String\n\t\t\t\/\/\"SERVLIST\" = (Maybe (String, Maybe String))\n\t\t\t\/\/\"SQUERY\" = String String\n\/\/\t\t\t\"SQUIRT\" = command0 REHASH args\n\t\t\t\/\/\"SQUIT\" = String String\n\t\t\t\/\/\"STATS\" = (Maybe (String, Maybe String))\n\t\t\t\/\/\"SUMMON\" = String (Maybe (String, Maybe String))\n\t\t\t\/\/\"TIME\" = (Maybe String)\n\t\t\t\/\/\"TOPIC\" = String (Maybe String)\n\t\t\t\/\/\"TRACE\" = (Maybe String)\n\t\t\t\/\/\"USER\" = String String String\n\t\t\t\/\/\"USERHOST\" = [String]\n\t\t\t\/\/\"USERS\" = (Maybe String)\n\t\t\t\/\/\"VERSION\" = (Maybe String)\n\t\t\t\/\/\"WALLOPS\" = String\n\t\t\t\/\/\"WHO\" = (Maybe String)\n\t\t\t\/\/\"WHOIS\" = (Maybe String) [String]\n\t\t\t\/\/\"WHOWAS\" = (Maybe String) [String]\n\nparseReply :: Parser Char IRCNumReply\nparseReply = (toString <$> pSome pDigit)\n\t>>= \\rep->pMiddle\n\t>>= \\recipient->spaceParser >>| (toString <$> pSome (pNoneOf illegal))\n\t>>= \\msg->pure {IRCNumReply|irc_reply=fs rep,irc_recipient=recipient,irc_message=msg}\n\twhere\n\t\tfs :: String -> IRCReplies\n\t\tfs s = fromInt $ toInt s\n\nspaceParser :: Parser Char [Char]\nspaceParser = pMany $ pToken ' '\n\nparseServer :: Parser Char String\nparseServer = pFail\n\nparseEither :: (Parser a b) (Parser a c) -> Parser a (Either b c)\nparseEither p q = Left <$> p <|> Right <$> q\n\nparseUser :: Parser Char IRCUser\nparseUser = parseNick\n\t\t>>= \\nick->optional (pToken '!' >>| parseUsr)\n\t\t>>= \\muser->optional (pToken '@' >>| parseHost)\n\t\t>>= \\mhost->pure {IRCUser | irc_nick=nick, irc_user=muser, irc_host=mhost}\n\nparseUsr :: Parser Char String\nparseUsr = toString <$> pSome (pNoneOf [' ', '@':illegal])\n\nparseNick :: Parser Char String\nparseNick = pAlpha >>= \\c->pMany (pAlpha <|> pDigit <|> pSpecial)\n\t>>= \\cs->pure (toString [c:cs])\n\npSpecial :: Parser Char Char\npSpecial = pOneOf ['-', '[', ']', '\\\\', '\\`', '^', '{', '}']\n\nparseHost :: Parser Char String\nparseHost = jon \".\" <$> pSepBy parseName (pToken '.')\n\twhere\n\t\tparseName :: Parser Char String\n\t\tparseName = toString <$> pSome (pAlpha <|> pDigit <|> pOneOf ['-'])\n\ninstance toString IRCNumReply where\n\ttoString m = toInt m.irc_reply <+ \" \" <+ m.irc_recipient <+ \" \" <+ formatMSG m.irc_message\ninstance toString IRCMessage where\n\ttoString m = maybe \"\" (\\s->either ((<+) \":\") id s <+ \" \") m.irc_prefix\n\t\t<+ either toString toString m.irc_command\n\ninstance toString IRCUser where\n\ttoString m = m.irc_nick <+ maybe \"\" ((<+) \"!\") m.irc_user\n\t\t<+ maybe \"\" ((<+) \"@\") m.irc_host\n\ncons :: a [a] -> [a]\ncons a as = [a:as]\n\npMiddle :: Parser Char String\npMiddle = fmap toString $\n\tspaceParser >>| liftM2 cons (pNotSatisfy ((==)':')) (pMany $ pNoneOf [' ':illegal])\n\npTrailing :: Parser Char String\npTrailing = fmap toString $ \n\tspaceParser >>| pToken ':' >>| pMany (pNoneOf illegal)\n\npParam :: Parser Char String\npParam = pMiddle <|> pTrailing\n\npNoneOf :: [a] -> Parser a a | Eq a\npNoneOf l = pSatisfy (not o flip isMember l)\n\npNotSatisfy :: (a -> Bool) -> Parser a a | Eq a\npNotSatisfy f = pSatisfy (not o f)\n\npInt :: Parser Char Int\npInt = toInt o toString <$> (spaceParser >>| pSome pDigit)\n\nillegal :: [Char]\nillegal = ['\\x00','\\r','\\n']\n\ninstance toString IRCCommand where\n\ttoString r = jon \" \" (print r) +++ \"\\r\\n\"\n\nprint :: IRCCommand -> [String]\nprint r = case r of\n\t\tADMIN mm = [\"ADMIN\":maybeToList mm]\n\t\tAWAY m = [\"AWAY\",m]\n\t\/\/CONNECT String (Maybe (Int, Maybe String))\n\t\/\/DIE \n\t\/\/ERROR String\n\t\/\/INFO (Maybe String)\n\t\/\/INVITE String String\n\t\/\/ISON [String]\n\t\tJOIN chs = [\"JOIN\",if (isEmpty chs) \"0\"\n\t\t\t(jon \", \" [jon \" \" [ch:maybeToList mk]\\\\(ch, mk)<-chs])]\n\t\/\/KICK String String (Maybe String)\n\t\/\/KILL String String\n\t\/\/LINKS (Maybe (Maybe String, String))\n\t\/\/LIST (Maybe ([String], Maybe String))\n\t\/\/LUSERS (Maybe (String, Maybe String))\n\t\/\/MODE String String (Maybe String) (Maybe String) (Maybe String)\n\t\/\/MOTD (Maybe String)\n\t\/\/NAMES [String]\n\t\tNICK n ms = [\"NICK\", n]\n\t\/\/NJOIN \n\t\/\/NOTICE String String\n\t\/\/OPER String String \n\t\/\/PART [String]\n\t\/\/PASS String\n\t\tPING a mb = [\"PING\",a:maybeToList mb]\n\t\tPONG a mb = [\"PONG\",a:maybeToList mb]\n\t\tPRIVMSG dest msg = [\"PRIVMSG\",jon \",\" dest,formatMSG msg]\n\t\tQUIT msg = [\"QUIT\":maybeToList msg]\n\t\/\/REHASH \n\t\/\/RESTART \n\t\/\/SERVER \n\t\/\/SERVICE String String String String\n\t\/\/SERVLIST (Maybe (String, Maybe String))\n\t\/\/SQUERY String String\n\t\/\/SQUIRT \n\t\/\/SQUIT String String\n\t\/\/STATS (Maybe (String, Maybe String))\n\t\/\/SUMMON String (Maybe (String, Maybe String))\n\t\/\/TIME (Maybe String)\n\t\/\/TOPIC String (Maybe String)\n\t\/\/TRACE (Maybe String)\n\t\tUSER login mode rn = [\"USER\", login, mode, \"*\", \":\"+++rn]\n\t\/\/USERHOST [String]\n\t\/\/USERS (Maybe String)\n\t\/\/VERSION (Maybe String)\n\t\/\/WALLOPS String\n\t\/\/WHO (Maybe String)\n\t\/\/WHOIS (Maybe String) [String]\n\t\/\/WHOWAS (Maybe String) [String]\n\t\t_ = [printToString r]\n\nformatMSG :: String -> String\nformatMSG s = if (indexOf \" \" s > 0 || indexOf \" \" s > 0) (\":\" +++ s) s\n\n\ninstance toString IRCReplies where toString r = printToString r\ninstance toString IRCErrors where toString r = printToString r\n\ninstance fromInt IRCReplies where\n\tfromInt r = case r of \n\t\t1 = RPL_WELCOME\n\t\t2 = RPL_YOURHOST\n\t\t3 = RPL_CREATED\n\t\t4 = RPL_MYINFO\n\t\t5 = RPL_BOUNCE\n\t\t200 = RPL_TRACELINK\n\t\t201 = RPL_TRACECONNECTING\n\t\t202 = RPL_TRACEHANDSHAKE\n\t\t203 = RPL_TRACEUNKNOWN\n\t\t204 = RPL_TRACEOPERATOR\n\t\t205 = RPL_TRACEUSER\n\t\t206 = RPL_TRACESERVER\n\t\t207 = RPL_TRACESERVICE\n\t\t208 = RPL_TRACENEWTYPE\n\t\t209 = RPL_TRACECLASS\n\t\t210 = RPL_TRACERECONNECT\n\t\t211 = RPL_STATSLINKINFO\n\t\t212 = RPL_STATSCOMMANDS\n\t\t219 = RPL_ENDOFSTATS\n\t\t221 = RPL_UMODEIS\n\t\t234 = RPL_SERVLIST\n\t\t235 = RPL_SERVLISTEND\n\t\t242 = RPL_STATSUPTIME\n\t\t243 = RPL_STATSOLINE\n\t\t251 = RPL_LUSERCLIENT\n\t\t252 = RPL_LUSEROP\n\t\t253 = RPL_LUSERUNKNOWN\n\t\t254 = RPL_LUSERCHANNELS\n\t\t255 = RPL_LUSERME\n\t\t256 = RPL_ADMINME\n\t\t257 = RPL_ADMINLOC1\n\t\t258 = RPL_ADMINLOC2\n\t\t259 = RPL_ADMINEMAIL\n\t\t261 = RPL_TRACELOG\n\t\t262 = RPL_TRACEEND\n\t\t263 = RPL_TRYAGAIN\n\t\t301 = RPL_AWAY\n\t\t302 = RPL_USERHOST\n\t\t303 = RPL_ISON\n\t\t304 = RPL_UNAWAY\n\t\t305 = RPL_NOWAWAY\n\t\t311 = RPL_WHOISUSER\n\t\t312 = RPL_WHOISSERVER\n\t\t313 = RPL_WHOISOPERATOR\n\t\t314 = RPL_WHOWASUSER\n\t\t315 = RPL_ENDOFWHO\n\t\t317 = RPL_WHOISIDLE\n\t\t318 = RPL_ENDOFWHOIS\n\t\t319 = RPL_WHOISCHANNELS\n\t\t321 = RPL_LISTSTART\n\t\t322 = RPL_LIST\n\t\t323 = RPL_LISTEND\n\t\t324 = RPL_CHANNELMODEIS\n\t\t325 = RPL_UNIQOPIS\n\t\t331 = RPL_NOTOPIC\n\t\t332 = RPL_TOPIC\n\t\t341 = RPL_INVITING\n\t\t342 = RPL_SUMMONING\n\t\t346 = RPL_INVITELIST\n\t\t347 = RPL_ENDOFINVITELIST\n\t\t348 = RPL_EXCEPTLIST\n\t\t349 = RPL_ENDOFEXCEPTLIST\n\t\t351 = RPL_VERSION\n\t\t352 = RPL_WHOREPLY\n\t\t353 = RPL_NAMREPLY\n\t\t364 = RPL_LINKS\n\t\t365 = RPL_ENDOFLINKS\n\t\t366 = RPL_ENDOFNAMES\n\t\t367 = RPL_BANLIST\n\t\t368 = RPL_ENDOFBANLIST\n\t\t369 = RPL_ENDOFWHOWAS\n\t\t371 = RPL_INFO\n\t\t372 = RPL_MOTD\n\t\t374 = RPL_ENDOFINFO\n\t\t375 = RPL_MOTDSTART\n\t\t376 = RPL_ENDOFMOTD\n\t\t381 = RPL_YOUREOPER\n\t\t382 = RPL_REHASHING\n\t\t383 = RPL_YOURESERVICE\n\t\t391 = RPL_TIME\n\t\t392 = RPL_USERSSTART\n\t\t393 = RPL_USERS\n\t\t394 = RPL_ENDOFUSERS\n\t\t395 = RPL_NOUSERS\n\t\t_ = undef\n\ninstance toInt IRCReplies where\n\ttoInt r = case r of \n\t\tRPL_WELCOME = 1\n\t\tRPL_YOURHOST = 2\n\t\tRPL_CREATED = 3\n\t\tRPL_MYINFO = 4\n\t\tRPL_BOUNCE = 5\n\t\tRPL_TRACELINK = 200\n\t\tRPL_TRACECONNECTING = 201\n\t\tRPL_TRACEHANDSHAKE = 202\n\t\tRPL_TRACEUNKNOWN = 203\n\t\tRPL_TRACEOPERATOR = 204\n\t\tRPL_TRACEUSER = 205\n\t\tRPL_TRACESERVER = 206\n\t\tRPL_TRACESERVICE = 207\n\t\tRPL_TRACENEWTYPE = 208\n\t\tRPL_TRACECLASS = 209\n\t\tRPL_TRACERECONNECT = 210\n\t\tRPL_STATSLINKINFO = 211\n\t\tRPL_STATSCOMMANDS = 212\n\t\tRPL_ENDOFSTATS = 219\n\t\tRPL_UMODEIS = 221\n\t\tRPL_SERVLIST = 234\n\t\tRPL_SERVLISTEND = 234\n\t\tRPL_STATSUPTIME = 242\n\t\tRPL_STATSOLINE = 243\n\t\tRPL_LUSERCLIENT = 251\n\t\tRPL_LUSEROP = 252\n\t\tRPL_LUSERUNKNOWN = 253\n\t\tRPL_LUSERCHANNELS = 254\n\t\tRPL_LUSERME = 255\n\t\tRPL_ADMINME = 256\n\t\tRPL_ADMINLOC1 = 257\n\t\tRPL_ADMINLOC2 = 258\n\t\tRPL_ADMINEMAIL = 259\n\t\tRPL_TRACELOG = 261\n\t\tRPL_TRACEEND = 262\n\t\tRPL_TRYAGAIN = 263\n\t\tRPL_AWAY = 301\n\t\tRPL_USERHOST = 302\n\t\tRPL_ISON = 303\n\t\tRPL_UNAWAY = 304\n\t\tRPL_NOWAWAY = 305\n\t\tRPL_WHOISUSER = 311\n\t\tRPL_WHOISSERVER = 312\n\t\tRPL_WHOISOPERATOR = 313\n\t\tRPL_WHOWASUSER = 314\n\t\tRPL_ENDOFWHO = 315\n\t\tRPL_WHOISIDLE = 317\n\t\tRPL_ENDOFWHOIS = 318\n\t\tRPL_WHOISCHANNELS = 319\n\t\tRPL_LISTSTART = 321\n\t\tRPL_LIST = 322\n\t\tRPL_LISTEND = 323\n\t\tRPL_CHANNELMODEIS = 324\n\t\tRPL_UNIQOPIS = 325\n\t\tRPL_NOTOPIC = 331\n\t\tRPL_TOPIC = 332\n\t\tRPL_INVITING = 341\n\t\tRPL_SUMMONING = 342\n\t\tRPL_INVITELIST = 346\n\t\tRPL_ENDOFINVITELIST = 347\n\t\tRPL_EXCEPTLIST = 348\n\t\tRPL_ENDOFEXCEPTLIST = 349\n\t\tRPL_VERSION = 351\n\t\tRPL_WHOREPLY = 352\n\t\tRPL_NAMREPLY = 353\n\t\tRPL_LINKS = 364\n\t\tRPL_ENDOFLINKS = 365\n\t\tRPL_ENDOFNAMES = 366\n\t\tRPL_BANLIST = 367\n\t\tRPL_ENDOFBANLIST = 367\n\t\tRPL_ENDOFWHOWAS = 369\n\t\tRPL_INFO = 371\n\t\tRPL_MOTD = 372\n\t\tRPL_ENDOFINFO = 374\n\t\tRPL_MOTDSTART = 375\n\t\tRPL_ENDOFMOTD = 376\n\t\tRPL_YOUREOPER = 381\n\t\tRPL_REHASHING = 382\n\t\tRPL_YOURESERVICE = 383\n\t\tRPL_TIME = 391\n\t\tRPL_USERSSTART = 392\n\t\tRPL_USERS = 393\n\t\tRPL_ENDOFUSERS = 394\n\t\tRPL_NOUSERS = 395\n\ninstance fromInt IRCErrors where\n\tfromInt r = case r of\n\t\t401 = ERR_NOSUCHNICK\n\t\t402 = ERR_NOSUCHSERVER\n\t\t403 = ERR_NOSUCHCHANNEL\n\t\t404 = ERR_CANNOTSENDTOCHAN\n\t\t405 = ERR_TOOMANYCHANNELS\n\t\t406 = ERR_WASNOSUCHNICK\n\t\t407 = ERR_TOOMANYTARGETS\n\t\t408 = ERR_NOSUCHSERVICE\n\t\t409 = ERR_NOORIGIN\n\t\t411 = ERR_NORECIPIENT\n\t\t412 = ERR_NOTEXTTOSEND\n\t\t413 = ERR_NOTOPLEVEL\n\t\t414 = ERR_WILDTOPLEVEL\n\t\t415 = ERR_BADMASK\n\t\t421 = ERR_UNKNOWNCOMMAND\n\t\t422 = ERR_NOMOTD\n\t\t423 = ERR_NOADMININFO\n\t\t424 = ERR_FILEERROR\n\t\t431 = ERR_NONICKNAMEGIVEN\n\t\t432 = ERR_ERRONEUSNICKNAME\n\t\t433 = ERR_NICKNAMEINUSE\n\t\t436 = ERR_NICKCOLLISION\n\t\t437 = ERR_UNAVAILRESOURCE\n\t\t441 = ERR_USERNOTINCHANNEL\n\t\t442 = ERR_NOTONCHANNEL\n\t\t443 = ERR_USERONCHANNEL\n\t\t444 = ERR_NOLOGIN\n\t\t445 = ERR_SUMMONDISABLED\n\t\t446 = ERR_USERSDISABLED\n\t\t451 = ERR_NOTREGISTERED\n\t\t461 = ERR_NEEDMOREPARAMS\n\t\t462 = ERR_ALREADYREGISTRED\n\t\t463 = ERR_NOPERMFORHOST\n\t\t464 = ERR_PASSWDMISMATCH\n\t\t465 = ERR_YOUREBANNEDCREEP\n\t\t466 = ERR_YOUWILLBEBANNED\n\t\t467 = ERR_KEYSET\n\t\t471 = ERR_CHANNELISFULL\n\t\t472 = ERR_UNKNOWNMODE\n\t\t473 = ERR_INVITEONLYCHAN\n\t\t474 = ERR_BANNEDFROMCHAN\n\t\t475 = ERR_BADCHANNELKEY\n\t\t476 = ERR_BADCHANMASK\n\t\t477 = ERR_NOCHANMODES\n\t\t478 = ERR_BANLISTFULL\n\t\t481 = ERR_NOPRIVILEGES\n\t\t482 = ERR_CHANOPRIVSNEEDED\n\t\t483 = ERR_CANTKILLSERVER\n\t\t484 = ERR_RESTRICTED\n\t\t485 = ERR_UNIQOPPRIVSNEEDED\n\t\t491 = ERR_NOOPERHOST\n\t\t501 = ERR_UMODEUNKNOWNFLAG\n\t\t502 = ERR_USERSDONTMATCH\n\ninstance toInt IRCErrors where\n\ttoInt r = case r of\n\t\tERR_NOSUCHNICK = 401\n\t\tERR_NOSUCHSERVER = 402\n\t\tERR_NOSUCHCHANNEL = 403\n\t\tERR_CANNOTSENDTOCHAN = 404\n\t\tERR_TOOMANYCHANNELS = 405\n\t\tERR_WASNOSUCHNICK = 406\n\t\tERR_TOOMANYTARGETS = 407\n\t\tERR_NOSUCHSERVICE = 408\n\t\tERR_NOORIGIN = 409\n\t\tERR_NORECIPIENT = 411\n\t\tERR_NOTEXTTOSEND = 412\n\t\tERR_NOTOPLEVEL = 413\n\t\tERR_WILDTOPLEVEL = 414\n\t\tERR_BADMASK = 415\n\t\tERR_UNKNOWNCOMMAND = 421\n\t\tERR_NOMOTD = 422\n\t\tERR_NOADMININFO = 423\n\t\tERR_FILEERROR = 424\n\t\tERR_NONICKNAMEGIVEN = 431\n\t\tERR_ERRONEUSNICKNAME = 432\n\t\tERR_NICKNAMEINUSE = 433\n\t\tERR_NICKCOLLISION = 436\n\t\tERR_UNAVAILRESOURCE = 437\n\t\tERR_USERNOTINCHANNEL = 441\n\t\tERR_NOTONCHANNEL = 442\n\t\tERR_USERONCHANNEL = 443\n\t\tERR_NOLOGIN = 444\n\t\tERR_SUMMONDISABLED = 445\n\t\tERR_USERSDISABLED = 446\n\t\tERR_NOTREGISTERED = 451\n\t\tERR_NEEDMOREPARAMS = 461\n\t\tERR_ALREADYREGISTRED = 462\n\t\tERR_NOPERMFORHOST = 463\n\t\tERR_PASSWDMISMATCH = 464\n\t\tERR_YOUREBANNEDCREEP = 465\n\t\tERR_YOUWILLBEBANNED = 466\n\t\tERR_KEYSET = 467\n\t\tERR_CHANNELISFULL = 471\n\t\tERR_UNKNOWNMODE = 472\n\t\tERR_INVITEONLYCHAN = 473\n\t\tERR_BANNEDFROMCHAN = 474\n\t\tERR_BADCHANNELKEY = 475\n\t\tERR_BADCHANMASK = 476\n\t\tERR_NOCHANMODES = 477\n\t\tERR_BANLISTFULL = 478\n\t\tERR_NOPRIVILEGES = 481\n\t\tERR_CHANOPRIVSNEEDED = 482\n\t\tERR_CANTKILLSERVER = 483\n\t\tERR_RESTRICTED = 484\n\t\tERR_UNIQOPPRIVSNEEDED = 485\n\t\tERR_NOOPERHOST = 491\n\t\tERR_UMODEUNKNOWNFLAG = 501\n\t\tERR_USERSDONTMATCH = 502\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"0fb4400c1e057e66f42ee9e8b5fb90df565e0b07","subject":"Fix ABC code example","message":"Fix ABC code example\n","repos":"clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/Builtins.icl","new_file":"backend\/Builtins.icl","new_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [FunctionEntry]\nbuiltin_functions =\n\t[ { zero\n\t & fe_loc=Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []\n\t }\n\t, { zero\n\t & fe_loc=Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]\n\t }\n\t]\n\nbuiltin_classes :: [ClassEntry]\nbuiltin_classes =\n\t[ { ce_loc=Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , ce_vars=[\"v\"]\n\t , ce_is_meta=False\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t , ce_usages=[]\n\t }\n\t]\n\nbuiltin_types :: [TypeDefEntry]\nbuiltin_types =\n\t[ { deft\n\t & tde_loc=Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t, { deft & tde_loc=Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Int\"}\n\t, { deft & tde_loc=Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Real\"}\n\t, { deft & tde_loc=Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Char\"}\n\t, { deft & tde_loc=Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], tde_typedef.td_name = \"Dynamic\"}\n\t, { deft & tde_loc=Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"File\"}\n\t, { deft\n\t & tde_loc=Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"]\n\t , tde_typedef.td_name = \"String\"\n\t , tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) }\n\t, { deft\n\t & tde_loc=Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"World\"\n\t , tde_typedef.td_uniq = True\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\"\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"]\n\t , tde_typedef.td_name = \"(->)\"\n\t , tde_typedef.td_args = [Var \"a\", Var \"b\"]\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\"\n\t , vars = [\"The argument type\", \"The result type\"]\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"()\" []\n\t , tde_typedef.td_name=\"_Unit\"\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The void \/ unit type.\"\n\t }\n\t , tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]\n\t }\n\t: lists\n\t++ arrays\n\t++ tuples\n\t]\nwhere\n\tdeft =\n\t\t{ tde_loc=zero\n\t\t, tde_typedef=\n\t\t\t{ td_name=\"\"\n\t\t\t, td_uniq=False\n\t\t\t, td_args=[]\n\t\t\t, td_rhs=TDRAbstract Nothing\n\t\t\t}\n\t\t, tde_doc=Nothing\n\t\t, tde_instances=[]\n\t\t, tde_derivations=[]\n\t\t, tde_usages=[]\n\t\t}\n\tdefc =\n\t\t{ cons_name=\"\"\n\t\t, cons_args=[]\n\t\t, cons_exi_vars=[]\n\t\t, cons_context=[]\n\t\t, cons_priority=Nothing\n\t\t}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> TypeDefEntry\n\t\tmake_list k s =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the list elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> TypeDefEntry\n\t\tmake_array k =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the array elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> TypeDefEntry\n\t\tmake_tuple n =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"]\n\t\t\t, tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t\t\"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t\t\"Clean supports tuples of arity 2 to 32.\"\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\"]\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [FunctionEntry]\nbuiltin_functions =\n\t[ { zero\n\t & fe_loc=Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []\n\t }\n\t, { zero\n\t & fe_loc=Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]\n\t }\n\t]\n\nbuiltin_classes :: [ClassEntry]\nbuiltin_classes =\n\t[ { ce_loc=Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , ce_vars=[\"v\"]\n\t , ce_is_meta=False\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t , ce_usages=[]\n\t }\n\t]\n\nbuiltin_types :: [TypeDefEntry]\nbuiltin_types =\n\t[ { deft\n\t & tde_loc=Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t, { deft & tde_loc=Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Int\"}\n\t, { deft & tde_loc=Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Real\"}\n\t, { deft & tde_loc=Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Char\"}\n\t, { deft & tde_loc=Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], tde_typedef.td_name = \"Dynamic\"}\n\t, { deft & tde_loc=Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"File\"}\n\t, { deft\n\t & tde_loc=Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"]\n\t , tde_typedef.td_name = \"String\"\n\t , tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) }\n\t, { deft\n\t & tde_loc=Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"World\"\n\t , tde_typedef.td_uniq = True\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\"\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"]\n\t , tde_typedef.td_name = \"(->)\"\n\t , tde_typedef.td_args = [Var \"a\", Var \"b\"]\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\"\n\t , vars = [\"The argument type\", \"The result type\"]\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"()\" []\n\t , tde_typedef.td_name=\"_Unit\"\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The void \/ unit type.\"\n\t }\n\t , tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]\n\t }\n\t: lists\n\t++ arrays\n\t++ tuples\n\t]\nwhere\n\tdeft =\n\t\t{ tde_loc=zero\n\t\t, tde_typedef=\n\t\t\t{ td_name=\"\"\n\t\t\t, td_uniq=False\n\t\t\t, td_args=[]\n\t\t\t, td_rhs=TDRAbstract Nothing\n\t\t\t}\n\t\t, tde_doc=Nothing\n\t\t, tde_instances=[]\n\t\t, tde_derivations=[]\n\t\t, tde_usages=[]\n\t\t}\n\tdefc =\n\t\t{ cons_name=\"\"\n\t\t, cons_args=[]\n\t\t, cons_exi_vars=[]\n\t\t, cons_context=[]\n\t\t, cons_priority=Nothing\n\t\t}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> TypeDefEntry\n\t\tmake_list k s =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the list elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> TypeDefEntry\n\t\tmake_array k =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the array elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> TypeDefEntry\n\t\tmake_tuple n =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"]\n\t\t\t, tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t\t\"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t\t\"Clean supports tuples of arity 2 to 32.\"\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\"]\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"1bb0610593417a74ae13384888ad46c1d5becf37","subject":"Fix #4: reply to private messages","message":"Fix #4: reply to private messages\n","repos":"clean-cloogle\/clean-irc","old_file":"cloogle.icl","new_file":"cloogle.icl","new_contents":"module cloogle\n\nimport Cloogle\nimport GenPrint\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nimport Data.Either\nfrom Data.Func import $, mapSt\nfrom Text import class Text(..), instance Text String, instance + String\n\nimport Internet.HTTP\n\nimport Text.JSON\n\nimport Text.URI\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad, instance Monad Maybe\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\nimport IRC\nimport IRCBot\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# s = if (startsWith \"http:\/\/\" s) s (if (startsWith \"https:\/\/\" s) s (\"http:\/\/\" + s))\n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doHTTPRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} 10000 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\ncloogle :: String *World -> (String, *World)\ncloogle data w\n# (mer, w) = doHTTPRequestL\n\t\t{ newHTTPRequest\n\t\t& req_path = \"\/api.php\"\n\t\t, req_query = \"?str=\" + urlEncode data\n\t\t, req_headers = 'DM'.fromList [(\"User-Agent\", \"cloogle-irc\")]\n\t\t, server_name = \"cloogle.org\"\n\t\t, server_port = 80} 10000 10 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= case fromJSON $ fromString resp.HTTPResponse.rsp_data of\n\tNothing = (\"couldn't parse json\", w)\n\tJust clr = (\"Results for \" + data + \" -- https:\/\/cloogle.org\/#\" +\n\t\treplaceSubString \"+\" \"%20\" (urlEncode data) + \"\\n\" +\n\t\tprocessResults clr, w)\n\twhere\n\t\tprocessResults :: Response -> String\n\t\tprocessResults resp\n\t\t| resp.return > 127 = \"Failed: return code: \" + toString resp.return + \", \" + resp.msg\n\t\t= join \"\\n\" $ map processResult $ take 3 resp.data\n\t\t\n\t\tprocessResult :: Result -> String\n\t\tprocessResult (FunctionResult (br, {func}))\n\t\t\t= \"Function in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ func\n\t\tprocessResult (TypeResult (br, {type}))\n\t\t\t= \"Type in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ limitResults type\n\t\tprocessResult (ClassResult (br, {class_name,class_funs}))\n\t\t\t= \"Class in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ class_name +++ \" with \"\n\t\t\t\t+++ toString (length class_funs) +++ \" class functions\"\n\t\tprocessResult (ModuleResult (br, _))\n\t\t\t= \"Module in \" +++ br.library +++ \": \" +++ br.modul\n\n\t\tlimitResults :: String -> String\n\t\tlimitResults s\n\t\t# lines = split \"\\n\" s\n\t\t| length lines > 4 = limitResults (join \"\\n\" (take 3 lines) + \"\\n...\")\n\t\t= join \"\\n\" (map maxWidth lines)\n\t\t\n\t\tmaxWidth :: String -> String\n\t\tmaxWidth s\n\t\t| size s > 80 = subString 0 77 s + \"...\"\n\t\t= s\n\n\nStart :: *World -> (MaybeErrorString (), *World)\nStart w = bot (\"irc.freenode.net\", 6667) startup shutdown () process w\n\twhere\n\t\ttoPrefix c = {irc_prefix=Nothing,irc_command=Right c}\n\t\tstartup = map toPrefix\n\t\t\t[NICK \"clooglebot\" Nothing\n\t\t\t,USER \"cloogle\" \"cloogle\" \"cloogle\" \"Cloogle bot\"\n\t\t\t,JOIN (CSepList [\"#cloogle\", \"#cleanlang\"]) Nothing]\n\t\tshutdown = map toPrefix [QUIT $ Just \"Bye\"]\n\n\t\tprocess :: IRCMessage () *World -> (Maybe [IRCMessage], (), *World)\n\t\tprocess im s w = case im.irc_command of\n\t\t\tLeft numr = (Just [], (), w)\n\t\t\tRight cmd = case process` im.irc_prefix cmd w of\n\t\t\t\t(Nothing, w) = (Nothing, (), w)\n\t\t\t\t(Just cs, w) = (Just $ map toPrefix cs, (), w)\n\n\t\tprocess` :: (Maybe (Either IRCUser String)) IRCCommand *World -> (Maybe [IRCCommand], *World)\n\t\tprocess` (Just (Left user)) (PRIVMSG t m) w\n\t\t\t| m.[0] == '!'\n\t\t\t\t# (msgs, w) = realProcess (split \" \" $ m % (1, size m)) w\n\t\t\t\t= (Just $ map (PRIVMSG recipient) msgs, w)\n\t\t\t= (Just [], w)\n\t\twhere\n\t\t\trecipient = case (\\(CSepList [t:_]) -> t.[0]) t of\n\t\t\t\t'#' -> t\n\t\t\t\t_ -> CSepList [user.irc_nick]\n\t\tprocess` _ (PING t mt) w = (Just [PONG t mt], w)\n\t\tprocess` _ _ w = (Just [], w)\n\n\t\trealProcess :: [String] *World -> ([String], *World)\n\t\trealProcess [\"help\",x:xs] w = ((case x of\n\t\t\t\"help\" =\n\t\t\t\t[ \"Usage: !help [ARG]\"\n\t\t\t\t, \"Show this help, or the specific help of the argument\"]\n\t\t\t\"ping\" =\n\t\t\t\t[ \"Usage: !ping [ARG [ARG ...]]\"\n\t\t\t\t, \"Ping the bot, it will pong the arguments back\"]\n\t\t\t\"shorten\" =\n\t\t\t\t[ \"Usage: !shorten URL [URL [URL ...]]\"\n\t\t\t\t, \"Shorten the given urls with the cloo.gl url shortener\"]\n\t\t\t\"query\" =\n\t\t\t\t[ \"Usage: !query QUERY\"\n\t\t\t\t, \"Query QUERY in cloogle and return the results\"]\n\t\t\t\"restart\" =\n\t\t\t\t[ \"Usage: !restart\"\n\t\t\t\t, \"Restart the bot\"]\n\t\t\tx = [\"Unknown command: \" +++ x]\n\t\t\t), w)\n\t\trealProcess [\"help\"] w = (\n\t\t\t[\"Type !help cmd for command specific help\"\n\t\t\t,\"available commands: help, ping, shorten, query, restart\"], w)\n\t\trealProcess [\"ping\":xs] w = ([\"pong \" +++ join \" \" xs], w)\n\t\trealProcess [\"shorten\":xs] w = case xs of\n\t\t\t[] = ([\"shorten requires at least one argument\"], w)\n\t\t\txs = mapSt shorten xs w\n\t\trealProcess [\"query\":xs] w = case xs of\n\t\t\t[] = ([\"query requires one or more arguments\"], w)\n\t\t\txs = appFst (split \"\\n\") $ cloogle (join \" \" xs) w\n\t\trealProcess [\"restart\"] w = abort \"Restarted\"\n\t\trealProcess [\"restart\":_] w = ([\"restart takes no arguments\"], w)\n\t\trealProcess [c:_] w = ([join \" \" [\n\t\t\t\"Unknown cmd: \", c, \", type !help to get help\"]], w)\n","old_contents":"module cloogle\n\nimport Cloogle\nimport GenPrint\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nimport Data.Either\nfrom Data.Func import $, mapSt\nfrom Text import class Text(..), instance Text String, instance + String\n\nimport Internet.HTTP\n\nimport Text.JSON\n\nimport Text.URI\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad, instance Monad Maybe\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\nimport IRC\nimport IRCBot\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# s = if (startsWith \"http:\/\/\" s) s (if (startsWith \"https:\/\/\" s) s (\"http:\/\/\" + s))\n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doHTTPRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} 10000 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\ncloogle :: String *World -> (String, *World)\ncloogle data w\n# (mer, w) = doHTTPRequestL\n\t\t{ newHTTPRequest\n\t\t& req_path = \"\/api.php\"\n\t\t, req_query = \"?str=\" + urlEncode data\n\t\t, req_headers = 'DM'.fromList [(\"User-Agent\", \"cloogle-irc\")]\n\t\t, server_name = \"cloogle.org\"\n\t\t, server_port = 80} 10000 10 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= case fromJSON $ fromString resp.HTTPResponse.rsp_data of\n\tNothing = (\"couldn't parse json\", w)\n\tJust clr = (\"Results for \" + data + \" -- https:\/\/cloogle.org\/#\" +\n\t\treplaceSubString \"+\" \"%20\" (urlEncode data) + \"\\n\" +\n\t\tprocessResults clr, w)\n\twhere\n\t\tprocessResults :: Response -> String\n\t\tprocessResults resp\n\t\t| resp.return > 127 = \"Failed: return code: \" + toString resp.return + \", \" + resp.msg\n\t\t= join \"\\n\" $ map processResult $ take 3 resp.data\n\t\t\n\t\tprocessResult :: Result -> String\n\t\tprocessResult (FunctionResult (br, {func}))\n\t\t\t= \"Function in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ func\n\t\tprocessResult (TypeResult (br, {type}))\n\t\t\t= \"Type in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ limitResults type\n\t\tprocessResult (ClassResult (br, {class_name,class_funs}))\n\t\t\t= \"Class in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ class_name +++ \" with \"\n\t\t\t\t+++ toString (length class_funs) +++ \" class functions\"\n\t\tprocessResult (ModuleResult (br, _))\n\t\t\t= \"Module in \" +++ br.library +++ \": \" +++ br.modul\n\n\t\tlimitResults :: String -> String\n\t\tlimitResults s\n\t\t# lines = split \"\\n\" s\n\t\t| length lines > 4 = limitResults (join \"\\n\" (take 3 lines) + \"\\n...\")\n\t\t= join \"\\n\" (map maxWidth lines)\n\t\t\n\t\tmaxWidth :: String -> String\n\t\tmaxWidth s\n\t\t| size s > 80 = subString 0 77 s + \"...\"\n\t\t= s\n\n\nStart :: *World -> (MaybeErrorString (), *World)\nStart w = bot (\"irc.freenode.net\", 6667) startup shutdown () process w\n\twhere\n\t\ttoPrefix c = {irc_prefix=Nothing,irc_command=Right c}\n\t\tstartup = map toPrefix\n\t\t\t[NICK \"clooglebot\" Nothing\n\t\t\t,USER \"cloogle\" \"cloogle\" \"cloogle\" \"Cloogle bot\"\n\t\t\t,JOIN (CSepList [\"#cloogle\", \"#cleanlang\"]) Nothing]\n\t\tshutdown = map toPrefix [QUIT $ Just \"Bye\"]\n\n\t\tprocess :: IRCMessage () *World -> (Maybe [IRCMessage], (), *World)\n\t\tprocess im s w = case im.irc_command of\n\t\t\tLeft numr = (Just [], (), w)\n\t\t\tRight cmd = case process` cmd w of\n\t\t\t\t(Nothing, w) = (Nothing, (), w)\n\t\t\t\t(Just cs, w) = (Just $ map toPrefix cs, (), w)\n\n\t\tprocess` :: IRCCommand *World -> (Maybe [IRCCommand], *World)\n\t\tprocess` (PRIVMSG t m) w\n\t\t\t| m.[0] == '!'\n\t\t\t\t# (msgs, w) = realProcess (split \" \" $ m % (1, size m)) w\n\t\t\t\t= (Just $ map (PRIVMSG t) msgs, w)\n\t\t\t= (Just [], w)\n\t\tprocess` (PING t mt) w = (Just [PONG t mt], w)\n\t\tprocess` _ w = (Just [], w)\n\n\t\trealProcess :: [String] *World -> ([String], *World)\n\t\trealProcess [\"help\",x:xs] w = ((case x of\n\t\t\t\"help\" =\n\t\t\t\t[ \"Usage: !help [ARG]\"\n\t\t\t\t, \"Show this help, or the specific help of the argument\"]\n\t\t\t\"ping\" =\n\t\t\t\t[ \"Usage: !ping [ARG [ARG ...]]\"\n\t\t\t\t, \"Ping the bot, it will pong the arguments back\"]\n\t\t\t\"shorten\" =\n\t\t\t\t[ \"Usage: !shorten URL [URL [URL ...]]\"\n\t\t\t\t, \"Shorten the given urls with the cloo.gl url shortener\"]\n\t\t\t\"query\" =\n\t\t\t\t[ \"Usage: !query QUERY\"\n\t\t\t\t, \"Query QUERY in cloogle and return the results\"]\n\t\t\t\"restart\" =\n\t\t\t\t[ \"Usage: !restart\"\n\t\t\t\t, \"Restart the bot\"]\n\t\t\tx = [\"Unknown command: \" +++ x]\n\t\t\t), w)\n\t\trealProcess [\"help\"] w = (\n\t\t\t[\"Type !help cmd for command specific help\"\n\t\t\t,\"available commands: help, ping, shorten, query, restart\"], w)\n\t\trealProcess [\"ping\":xs] w = ([\"pong \" +++ join \" \" xs], w)\n\t\trealProcess [\"shorten\":xs] w = case xs of\n\t\t\t[] = ([\"shorten requires at least one argument\"], w)\n\t\t\txs = mapSt shorten xs w\n\t\trealProcess [\"query\":xs] w = case xs of\n\t\t\t[] = ([\"query requires one or more arguments\"], w)\n\t\t\txs = appFst (split \"\\n\") $ cloogle (join \" \" xs) w\n\t\trealProcess [\"restart\"] w = abort \"Restarted\"\n\t\trealProcess [\"restart\":_] w = ([\"restart takes no arguments\"], w)\n\t\trealProcess [c:_] w = ([join \" \" [\n\t\t\t\"Unknown cmd: \", c, \", type !help to get help\"]], w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"667f4acda66647bdfcac376afd0e3bf39cd8b1a8","subject":"VMS specific: make sure final release can be installed over daily build","message":"VMS specific: make sure final release can be installed over daily build\n","repos":"libssh2\/libssh2,libssh2\/libssh2,libssh2\/libssh2,libssh2\/libssh2","old_file":"vms\/libssh2_make_kit.dcl","new_file":"vms\/libssh2_make_kit.dcl","new_contents":"$!\n$ olddir = f$environment(\"default\")\n$ on error then goto End\n$!\n$ gosub Init\n$!\n$ call WriteProductDescriptionFile\n$ call WriteProductTextFile\n$!\n$! backup tree\n$!\n$ backup [-...]*.*;0\/excl=([]*.exe,*.obj,*.opt,*.hlp,*.hlb,*.bck,*.com,*.pcsi*) -\n libssh2-'versionname''datename'_src.bck\/save\n$ purge libssh2-'versionname''datename'_src.bck\n$!\n$! backup examples\n$!\n$ backup [-.example]*.c;0 libssh2_examples-'versionname''datename'.bck\/save\n$ dire libssh2_examples-'versionname''datename'.bck\n$ purge libssh2_examples-'versionname''datename'.bck\n$!\n$ set default [-]\n$!\n$ defdir = f$environment( \"default\" )\n$ thisdev = f$parse(defdir,,,\"device\",\"no_conceal\") \n$ thisdir = f$parse(defdir,,,\"directory\",\"no_conceal\") - \"][\" - \"][\" - \"][\" - \"][\"\n$!\n$ libssh2_kf = thisdev + thisdir \n$ libssh2_kf = libssh2_kf - \"]\" + \".]\"\n$!\n$ set default 'mdir'\n$!\n$ define\/translation_attributes=concealed libssh2_kf 'libssh2_kf'\n$!\n$ product package libssh2 - \n \/base='arch' - \n \/producer=jcb -\n \/source=[] - ! where to find PDF and PTF \n \/destination=[] - ! where to put .PCSI file \n \/material=libssh2_kf:[000000...] - ! where to find product material \n \/version=\"''vms_majorv'.''minorv'-''patchv'''datename'\" -\n \/format=sequential \n$!\n$End:\n$!\n$ set noon\n$ if f$search(\"*.pcsi$desc;*\") .nes. \"\" then delete *.pcsi$desc;*\n$ if f$search(\"*.pcsi$text;*\") .nes. \"\" then delete *.pcsi$text;*\n$ if f$search(\"libssh2-''versionname'''datename'_src.bck;*\") .nes. \"\" then delete libssh2-'versionname''datename'_src.bck;*\n$ if f$search(\"libssh2_examples-''versionname'''datename'.bck;*\") .nes. \"\" then delete libssh2_examples-'versionname''datename'.bck;*\n$!\n$ if f$trnlnm(\"libssh2_kf\") .nes. \"\" then deassign libssh2_kf\n$ set default 'olddir'\n$!\n$exit \n$!\n$!--------------------------------------------------------------------------------\n$!\n$Init:\n$ set process\/parse=extended\n$!\n$ say = \"write sys$output\"\n$!\n$ mdir = f$environment(\"procedure\") \n$ mdir = mdir - f$parse(mdir,,,\"name\") - f$parse(mdir,,,\"type\") - f$parse(mdir,,,\"version\")\n$!\n$ set default 'mdir'\n$!\n$ pipe search [-.include]*.h libssh2_version_major\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job majorv &l )\n$ pipe search [-.include]*.h libssh2_version_minor\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job minorv &l )\n$ pipe search [-.include]*.h libssh2_version_patch\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job patchv &l )\n$!\n$ majorv = f$trnlnm(\"majorv\")\n$ minorv = f$integer(f$trnlnm(\"minorv\")) \n$ patchv = f$integer( f$trnlnm(\"patchv\"))\n$!\n$ deassign\/job majorv\n$ deassign\/job minorv\n$ deassign\/job patchv\n$!\n$ vms_majorv = f$trnlnm(\"vms_majorv\")\n$ if vms_majorv .eqs. \"\" then vms_majorv = majorv\n$!\n$ arch = \"UNKNOWN\"\n$ if f$getsyi(\"arch_type\") .eq. 2 then arch = \"AXPVMS\"\n$ if f$getsyi(\"arch_type\") .eq. 3 then arch = \"I64VMS\"\n$!\n$ if arch .eqs. \"UNKNOWN\"\n$ then\n$ say \"Unsupported or unknown architecture, only works on Alpha and Itanium\"\n$ exit 2\n$ endif\n$!\n$! is this a proper release or a daily snapshot?\n$! crummy, but should work.\n$!\n$ daily = \"TRUE\"\n$ firstdash = f$locate(\"-\",mdir)\n$ restdir = f$extract( firstdash + 1, 80, mdir)\n$ seconddash = f$locate(\"-\", restdir)\n$ if seconddash .ge. f$length( restdir )\n$ then\n$ daily = \"FALSE\"\n$ datename = \"Final\"\n$ else\n$ datename = \"D\" + f$extract(seconddash+1,8,restdir) \n$ endif\n$!\n$ if daily \n$ then\n$ productname = \"JCB ''arch' LIBSSH2 V''vms_majorv'.''minorv'-''patchv'''datename'\"\n$ else\n$ productname = \"JCB ''arch' LIBSSH2 V''vms_majorv'.''minorv'-''patchv'''datename'\"\n$ endif\n$!\n$ productfilename = \"JCB-''arch'-LIBSSH2-\" + f$fao(\"V!2ZL!2ZL-!2ZL!AS-1\", f$integer(vms_majorv),minorv,patchv,datename)\n$!\n$ versionname = \"''vms_majorv'_''minorv'_''patchv'\"\n$!\n$return\n$!\n$!--------------------------------------------------------------------------------\n$!\n$WriteProductDescriptionFile: subroutine\n$!\n$ open\/write pd 'productfilename'.PCSI$DESC\n$!\n$ write pd \"product ''productname' full ;\"\n$ write pd \" software DEC ''arch' VMS ;\"\n$ write pd \" if (not ) ;\n$ write pd \" error NEED_VMS83 ;\"\n$ write pd \" end if ;\"\n$ write pd \" software HP ''arch' SSL version minimum V1.3;\"\n$ write pd \" if (not ) ;\n$ write pd \" error NEED_SSL ;\"\n$ write pd \" end if ;\"\n$ write pd \" execute preconfigure (\"\"set process\/parse_type=extended\"\");\"\n$ write pd \" execute postinstall (\"\"set process\/parse_type=extended\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv]usr.dir usr.DIR\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr]include.dir include.DIR\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.include]libssh2.dir libssh2.DIR\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.include.libssh2]libssh2.h libssh2.h\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.include.libssh2]libssh2_publickey.h libssh2_publickey.h\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.include.libssh2]libssh2_sftp.h libssh2_sftp.h\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.include.libssh2]libssh2_config.h libssh2_config.h\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr]lib.dir lib.DIR\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.lib]gnv$libssh2_''versionname'.exe gnv$libssh2_''versionname'.exe\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.share.doc.libssh2]libssh2.hlb libssh2.hlb\"\");\"\n$ write pd \" information RELEASE_NOTES phase after ;\"\n$ write pd \" option EXAMPLE default 0 ;\"\n$ write pd \" directory \"\"[gnv.usr.share.doc.libssh2.examples]\"\" ;\"\n$ write pd \" file \"\"[gnv.usr.share.doc.libssh2.examples]libssh2_examples-''versionname'''datename'.bck\"\";\"\n$ write pd \" end option ;\"\n$ write pd \" option SOURCE default 0 ;\"\n$ write pd \" directory \"\"[gnv.common_src]\"\" ;\"\n$ write pd \" file \"\"[gnv.common_src]libssh2-''versionname'''datename'_src.bck\"\";\"\n$ write pd \" end option ;\"\n$ write pd \" directory \"\"[gnv]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.lib]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.include]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.include.libssh2]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.share]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.share.doc]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.share.doc.libssh2]\"\" ;\"\n$ write pd \" file \"\"[gnv.usr.include.libssh2]libssh2.h\"\" source \"\"[include]libssh2.h\"\";\"\n$ write pd \" file \"\"[gnv.usr.include.libssh2]libssh2_publickey.h\"\" source \"\"[include]libssh2_publickey.h\"\";\"\n$ write pd \" file \"\"[gnv.usr.include.libssh2]libssh2_sftp.h\"\" source \"\"[include]libssh2_sftp.h\"\";\"\n$ write pd \" file \"\"[gnv.usr.include.libssh2]libssh2_config.h\"\" source \"\"[vms]libssh2_config.h\"\";\"\n$ write pd \" file \"\"[gnv.usr.share.doc.libssh2]libssh2.hlb\"\" source \"\"[vms]libssh2.hlb\"\";\"\n$ write pd \" file \"\"[gnv.usr.share.doc.libssh2]libssh2-''versionname'.news\"\" source \"\"[000000]NEWS.\"\";\"\n$ write pd \" file \"\"[gnv.usr.share.doc.libssh2]libssh2-''versionname'.release_notes\"\" source \"\"[vms]readme.vms\"\";\"\n$ write pd \" file \"\"[gnv.usr.lib]gnv$libssh2_''versionname'.exe\"\" source \"\"[vms]libssh2_''versionname'.exe\"\";\"\n$ write pd \"end product ;\"\n$ close pd\n$exit \n$endsubroutine\n$!\n$!--------------------------------------------------------------------------------\n$!\n$WriteProductTextFile: subroutine\n$!\n$ open\/write pt 'productfilename'.PCSI$TEXT\n$ write pt \"=PRODUCT ''productname' Full\"\n$ write pt \"1 'PRODUCER\"\n$ write pt \"=prompt libssh2 is an open source product ported to VMS by Jose Baars\"\n$ write pt \"This software product is provided with no warranty.\"\n$ write pt \"For license information see the LIBSSH2 help library.\"\n$ write pt \"1 'PRODUCT\"\n$ write pt \"=prompt JCB LIBSSH2 for OpenVMS\"\n$ write pt \"\"\n$ write pt \"libssh2 is an open source client side library that aims to implement\"\n$ write pt \"the SSH protocol. This is the OpenVMS port of that library.\"\n$ write pt \"Further information at http:\/\/www.libssh2.org.\"\n$ write pt \"\"\n$ write pt \"1 NEED_VMS83\"\n$ write pt \"=prompt OpenVMS 8.3 or later is not installed on your system.\"\n$ write pt \"This product requires OpenVMS 8.3 or later to function.\"\n$ write pt \"\"\n$ write pt \"1 NEED_SSL\"\n$ write pt \"=prompt HP SSL 1.3 or later is not installed on your system.\"\n$ write pt \"This product requires HP SSL 1.3 or later to function.\"\n$ write pt \"\"\n$ write pt \"1 RELEASE_NOTES\"\n$ write pt \"=prompt Release notes and the libssh2 help library are available in [gnv.usr.share.doc.libssh2] directory.\"\n$ write pt \"\"\n$ write pt \"1 EXAMPLE\"\n$ write pt \"=prompt Do you want the libssh2 C programming examples ? \"\n$ write pt \"The libssh2 coding examples will be available in backup saveset \"\n$ write pt \"[gnv.usr.share.doc.libssh2.examples]libssh2_examples_''versionname'.bck\"\n$ write pt \"\"\n$ write pt \"1 SOURCE\"\n$ write pt \"=prompt Do you want the complete libssh2 source tree ? \"\n$ write pt \"The libssh2 source tree will be available in backup saveset \"\n$ write pt \"[gnv.common_src]libssh2_''versionname'''datename'_src.bck\"\n$close pt\n$exit\n$ endsubroutine\n\n","old_contents":"$!\n$ olddir = f$environment(\"default\")\n$ on error then goto End\n$!\n$ gosub Init\n$!\n$ call WriteProductDescriptionFile\n$ call WriteProductTextFile\n$!\n$! backup tree\n$!\n$ backup [-...]*.*;0\/excl=([]*.exe,*.obj,*.opt,*.hlp,*.hlb,*.bck,*.com,*.pcsi*) -\n libssh2-'versionname''datename'_src.bck\/save\n$ purge libssh2-'versionname''datename'_src.bck\n$!\n$! backup examples\n$!\n$ backup [-.example]*.c;0 libssh2_examples-'versionname''datename'.bck\/save\n$ dire libssh2_examples-'versionname''datename'.bck\n$ purge libssh2_examples-'versionname''datename'.bck\n$!\n$ set default [-]\n$!\n$ defdir = f$environment( \"default\" )\n$ thisdev = f$parse(defdir,,,\"device\",\"no_conceal\") \n$ thisdir = f$parse(defdir,,,\"directory\",\"no_conceal\") - \"][\" - \"][\" - \"][\" - \"][\"\n$!\n$ libssh2_kf = thisdev + thisdir \n$ libssh2_kf = libssh2_kf - \"]\" + \".]\"\n$!\n$ set default 'mdir'\n$!\n$ define\/translation_attributes=concealed libssh2_kf 'libssh2_kf'\n$!\n$ product package libssh2 - \n \/base='arch' - \n \/producer=jcb -\n \/source=[] - ! where to find PDF and PTF \n \/destination=[] - ! where to put .PCSI file \n \/material=libssh2_kf:[000000...] - ! where to find product material \n \/version=\"''vms_majorv'.''minorv'-''patchv'''datename'\" -\n \/format=sequential \n$!\n$End:\n$!\n$ set noon\n$ if f$search(\"*.pcsi$desc;*\") .nes. \"\" then delete *.pcsi$desc;*\n$ if f$search(\"*.pcsi$text;*\") .nes. \"\" then delete *.pcsi$text;*\n$ if f$search(\"libssh2-''versionname'''datename'_src.bck;*\") .nes. \"\" then delete libssh2-'versionname''datename'_src.bck;*\n$ if f$search(\"libssh2_examples-''versionname'''datename'.bck;*\") .nes. \"\" then delete libssh2_examples-'versionname''datename'.bck;*\n$!\n$ if f$trnlnm(\"libssh2_kf\") .nes. \"\" then deassign libssh2_kf\n$ set default 'olddir'\n$!\n$exit \n$!\n$!--------------------------------------------------------------------------------\n$!\n$Init:\n$ set process\/parse=extended\n$!\n$ say = \"write sys$output\"\n$!\n$ mdir = f$environment(\"procedure\") \n$ mdir = mdir - f$parse(mdir,,,\"name\") - f$parse(mdir,,,\"type\") - f$parse(mdir,,,\"version\")\n$!\n$ set default 'mdir'\n$!\n$ pipe search [-.include]*.h libssh2_version_major\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job majorv &l )\n$ pipe search [-.include]*.h libssh2_version_minor\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job minorv &l )\n$ pipe search [-.include]*.h libssh2_version_patch\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job patchv &l )\n$!\n$ majorv = f$trnlnm(\"majorv\")\n$ minorv = f$integer(f$trnlnm(\"minorv\")) \n$ patchv = f$integer( f$trnlnm(\"patchv\"))\n$!\n$ deassign\/job majorv\n$ deassign\/job minorv\n$ deassign\/job patchv\n$!\n$ vms_majorv = f$trnlnm(\"vms_majorv\")\n$ if vms_majorv .eqs. \"\" then vms_majorv = majorv\n$!\n$ arch = \"UNKNOWN\"\n$ if f$getsyi(\"arch_type\") .eq. 2 then arch = \"AXPVMS\"\n$ if f$getsyi(\"arch_type\") .eq. 3 then arch = \"I64VMS\"\n$!\n$ if arch .eqs. \"UNKNOWN\"\n$ then\n$ say \"Unsupported or unknown architecture, only works on Alpha and Itanium\"\n$ exit 2\n$ endif\n$!\n$! is this a proper release or a daily snapshot?\n$! crummy, but should work.\n$!\n$ daily = \"TRUE\"\n$ firstdash = f$locate(\"-\",mdir)\n$ restdir = f$extract( firstdash + 1, 80, mdir)\n$ seconddash = f$locate(\"-\", restdir)\n$ if seconddash .ge. f$length( restdir )\n$ then\n$ daily = \"FALSE\"\n$ datename = \"\" \n$ else\n$ datename = \"D\" + f$extract(seconddash+1,8,restdir) \n$ endif\n$!\n$ if daily \n$ then\n$ productname = \"JCB ''arch' LIBSSH2 V''vms_majorv'.''minorv'-''patchv'''datename'\"\n$ else\n$ productname = \"JCB ''arch' LIBSSH2 V''vms_majorv'.''minorv'-''patchv'\"\n$ endif\n$!\n$ productfilename = \"JCB-''arch'-LIBSSH2-\" + f$fao(\"V!2ZL!2ZL-!2ZL!AS-1\", f$integer(vms_majorv),minorv,patchv,datename)\n$!\n$ versionname = \"''vms_majorv'_''minorv'_''patchv'\"\n$!\n$return\n$!\n$!--------------------------------------------------------------------------------\n$!\n$WriteProductDescriptionFile: subroutine\n$!\n$ open\/write pd 'productfilename'.PCSI$DESC\n$!\n$ write pd \"product ''productname' full ;\"\n$ write pd \" software DEC ''arch' VMS ;\"\n$ write pd \" if (not ) ;\n$ write pd \" error NEED_VMS83 ;\"\n$ write pd \" end if ;\"\n$ write pd \" software HP ''arch' SSL version minimum V1.3;\"\n$ write pd \" if (not ) ;\n$ write pd \" error NEED_SSL ;\"\n$ write pd \" end if ;\"\n$ write pd \" execute preconfigure (\"\"set process\/parse_type=extended\"\");\"\n$ write pd \" execute postinstall (\"\"set process\/parse_type=extended\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv]usr.dir usr.DIR\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr]include.dir include.DIR\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.include]libssh2.dir libssh2.DIR\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.include.libssh2]libssh2.h libssh2.h\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.include.libssh2]libssh2_publickey.h libssh2_publickey.h\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.include.libssh2]libssh2_sftp.h libssh2_sftp.h\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.include.libssh2]libssh2_config.h libssh2_config.h\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr]lib.dir lib.DIR\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.lib]gnv$libssh2_''versionname'.exe gnv$libssh2_''versionname'.exe\"\",\"\n$ write pd \" \"\"rename pcsi$destination:[gnv.usr.share.doc.libssh2]libssh2.hlb libssh2.hlb\"\");\"\n$ write pd \" information RELEASE_NOTES phase after ;\"\n$ write pd \" option EXAMPLE default 0 ;\"\n$ write pd \" directory \"\"[gnv.usr.share.doc.libssh2.examples]\"\" ;\"\n$ write pd \" file \"\"[gnv.usr.share.doc.libssh2.examples]libssh2_examples-''versionname'''datename'.bck\"\";\"\n$ write pd \" end option ;\"\n$ write pd \" option SOURCE default 0 ;\"\n$ write pd \" directory \"\"[gnv.common_src]\"\" ;\"\n$ write pd \" file \"\"[gnv.common_src]libssh2-''versionname'''datename'_src.bck\"\";\"\n$ write pd \" end option ;\"\n$ write pd \" directory \"\"[gnv]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.lib]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.include]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.include.libssh2]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.share]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.share.doc]\"\" ;\"\n$ write pd \" directory \"\"[gnv.usr.share.doc.libssh2]\"\" ;\"\n$ write pd \" file \"\"[gnv.usr.include.libssh2]libssh2.h\"\" source \"\"[include]libssh2.h\"\";\"\n$ write pd \" file \"\"[gnv.usr.include.libssh2]libssh2_publickey.h\"\" source \"\"[include]libssh2_publickey.h\"\";\"\n$ write pd \" file \"\"[gnv.usr.include.libssh2]libssh2_sftp.h\"\" source \"\"[include]libssh2_sftp.h\"\";\"\n$ write pd \" file \"\"[gnv.usr.include.libssh2]libssh2_config.h\"\" source \"\"[vms]libssh2_config.h\"\";\"\n$ write pd \" file \"\"[gnv.usr.share.doc.libssh2]libssh2.hlb\"\" source \"\"[vms]libssh2.hlb\"\";\"\n$ write pd \" file \"\"[gnv.usr.share.doc.libssh2]libssh2-''versionname'.news\"\" source \"\"[000000]NEWS.\"\";\"\n$ write pd \" file \"\"[gnv.usr.share.doc.libssh2]libssh2-''versionname'.release_notes\"\" source \"\"[vms]readme.vms\"\";\"\n$ write pd \" file \"\"[gnv.usr.lib]gnv$libssh2_''versionname'.exe\"\" source \"\"[vms]libssh2_''versionname'.exe\"\";\"\n$ write pd \"end product ;\"\n$ close pd\n$exit \n$endsubroutine\n$!\n$!--------------------------------------------------------------------------------\n$!\n$WriteProductTextFile: subroutine\n$!\n$ open\/write pt 'productfilename'.PCSI$TEXT\n$ write pt \"=PRODUCT ''productname' Full\"\n$ write pt \"1 'PRODUCER\"\n$ write pt \"=prompt libssh2 is an open source product ported to VMS by Jose Baars\"\n$ write pt \"This software product is provided with no warranty.\"\n$ write pt \"For license information see the LIBSSH2 help library.\"\n$ write pt \"1 'PRODUCT\"\n$ write pt \"=prompt JCB LIBSSH2 for OpenVMS\"\n$ write pt \"\"\n$ write pt \"libssh2 is an open source client side library that aims to implement\"\n$ write pt \"the SSH protocol. This is the OpenVMS port of that library.\"\n$ write pt \"Further information at http:\/\/www.libssh2.org.\"\n$ write pt \"\"\n$ write pt \"1 NEED_VMS83\"\n$ write pt \"=prompt OpenVMS 8.3 or later is not installed on your system.\"\n$ write pt \"This product requires OpenVMS 8.3 or later to function.\"\n$ write pt \"\"\n$ write pt \"1 NEED_SSL\"\n$ write pt \"=prompt HP SSL 1.3 or later is not installed on your system.\"\n$ write pt \"This product requires HP SSL 1.3 or later to function.\"\n$ write pt \"\"\n$ write pt \"1 RELEASE_NOTES\"\n$ write pt \"=prompt Release notes and the libssh2 help library are available in [gnv.usr.share.doc.libssh2] directory.\"\n$ write pt \"\"\n$ write pt \"1 EXAMPLE\"\n$ write pt \"=prompt Do you want the libssh2 C programming examples ? \"\n$ write pt \"The libssh2 coding examples will be available in backup saveset \"\n$ write pt \"[gnv.usr.share.doc.libssh2.examples]libssh2_examples_''versionname'.bck\"\n$ write pt \"\"\n$ write pt \"1 SOURCE\"\n$ write pt \"=prompt Do you want the complete libssh2 source tree ? \"\n$ write pt \"The libssh2 source tree will be available in backup saveset \"\n$ write pt \"[gnv.common_src]libssh2_''versionname'''datename'_src.bck\"\n$close pt\n$exit\n$ endsubroutine\n\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Clean"} {"commit":"53fb8f139161afd953855c42e456c93c6b8977e5","subject":"Also look at _Modules in builddb (e.g. _SystemArray)","message":"Also look at _Modules in builddb (e.g. _SystemArray)\n","repos":"dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle","old_file":"builddb.icl","new_file":"builddb.icl","new_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\n\n\/\/ StdEnv\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nfrom Text import class Text(concat), instance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String\nimport CoclUtils\n\n\/\/ frontend\n\/\/import Heap, compile, parse, predef\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents), ::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr, ::Position(NoPos), ::Module{mod_ident,mod_defs}, ::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class), ::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType, ::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_types}, ::Type, ::ClassDef{class_ident,class_args}, ::TypeVar\nfrom parse import wantModule\n\n:: CLI = {\n\thelp :: Bool,\n\tversion :: Bool,\n\troot :: String,\n\tlibs :: [String]}\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ \"StdEnv\"\n\t , \"StdLib\"\n\t , \"ArgEnv\"\n\t , \"Directory\"\n\t , \"Dynamics\"\n\t , \"Gast\"\n\t , \"Generics\"\n\t , \"MersenneTwister\"\n\t , \"TCPIP\"\n\t , \"clean-platform\/OS-Independent\"\n\t , \"clean-platform\/OS-Linux\"\n\t , \"clean-platform\/OS-Linux-32\"\n\t , \"clean-platform\/OS-Linux-64\"\n\t , \"clean-platform\/OS-Mac\"\n\t , \"clean-platform\/OS-Posix\"\n\t , \"clean-platform\/OS-Windows\"\n\t , \"clean-platform\/OS-Windows-32\"\n\t , \"clean-platform\/OS-Windows-64\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > builddb.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (mods, w) = findModules` cli.libs cli.root w\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop mods 'DB'.newDb cache w\n\t# f = 'DB'.saveDb db f\n\t= fclose f w\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: [(String,String)] 'DB'.TypeDB *DclCache *World -> *('DB'.TypeDB, *World)\n\tloop [] db _ w = (db,w)\n\tloop [(lib,mod):list] db cache w\n\t# (db, cache, w) = getModuleTypes mod lib cache db w\n\t= loop list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[x:c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\/\/ Libraries Library Module\nfindModules` :: ![String] !String !*World -> *(![(String,String)], !*World)\nfindModules` [] _ w = ([], w)\nfindModules` [lib:libs] root w\n#! (mods, w) = findModules lib root w\n#! (moremods, w) = findModules` libs root w\n= (removeDup (mods ++ moremods), w)\n\nfindModules :: !String !String !*World -> *(![(String,String)], !*World)\nfindModules lib root w\n#! (fps, w) = readDirectory (root +++ \"\/\" +++ lib) w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (tuple (root +++ lib)) $ map (\\s->s%(0,size s-5)) $ filter isDclModule fps\n#! (moremods, w) = findModules` (map ((+++) (lib+++\"\/\")) (filter isDirectory fps)) root w\n= (removeDup (mods ++ moremods), w)\nwhere\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String String *DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes mod lib cache db w\n# filename = lib +++ \"\/\" +++ mkdir mod +++ \".dcl\"\n# (ok,f,w) = fopen filename FReadText w\n| not ok = abort (\"Couldn't open file \" +++ filename +++ \".\\n\")\n# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n cache = {cache & hash_table=ht}\n# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" False mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n cache = {cache & hash_table=ht}\n# (ok,w) = fclose f w\n| not ok = abort (\"Couldn't close file \" +++ filename +++ \".\\n\")\n# mod = pm.mod_ident.id_name\n# db = 'DB'.putTypes (pd_typespecs mod pm.mod_defs) db\n# db = 'DB'.putInstancess (pd_instances mod pm.mod_defs) db\n# db = 'DB'.putClasses (pd_classes mod pm.mod_defs) db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = {if (c == '.') '\/' c\\\\c<-:s}\n\n\tpd_typespecs :: String [ParsedDefinition] -> [('DB'.FunctionLocation, 'DB'.Type)]\n\tpd_typespecs mod pds\n\t# pds = filter (\\pd->case pd of (PD_TypeSpec _ _ _ _ _)=True; _=False) pds\n\t# sts = map (\\(PD_TypeSpec pos id prio st funspecs) -> ('DB'.FL lib mod id.id_name,st)) pds\n\t# sts = filter (\\st->case st of (_,(Yes _))=True; _=False) sts\n\t# sts = map (\\(loc,Yes x)->(loc,'T'.toType x)) sts\n\t= sts\n\n\tpd_instances :: String [ParsedDefinition] -> [('DB'.Class, ['DB'.Type])]\n\tpd_instances mod pds\n\t# pds = filter (\\pd->case pd of (PD_Instance _)=True; _=False) pds\n\t= map (\\(PD_Instance {pim_pi={pi_ident,pi_types}})\n\t\t-> (pi_ident.id_name, map 'T'.toType pi_types)) pds\n\n\tpd_classes :: String [ParsedDefinition]\n\t\t-> [('DB'.ClassLocation, ['T'.TypeVar], [('DB'.FunctionName, 'T'.Type)])]\n\tpd_classes mod pds\n\t# pds = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) pds\n\t= map (\\(PD_Class {class_ident={id_name},class_args} pds)\n\t\t-> let typespecs = pd_typespecs mod pds\n\t\tin ('DB'.CL lib mod id_name, map 'T'.toTypeVar class_args, \n\t\t\t[(f,t) \\\\ ('DB'.FL _ _ f, t) <- typespecs])) pds\n\nunigroups :: (Type Type -> Bool) [(a,Type)] -> [([a],Type)]\nunigroups f ts = unigroups` ts []\nwhere\n\tunigroups` [] groups = groups\n\tunigroups` [(a,t):ts] [] = unigroups` ts [([a],t)]\n\tunigroups` [(a,t):ts] [(ns,ut):groups]\n\t| f t ut\t= unigroups` ts [([a:ns],ut):groups]\n\t| otherwise = unigroups` ts [(ns,ut):unigroups` [(a,t)] groups]\n\n(<+) infixr 5 :: a b -> [String] | print a & print b\n(<+) a b = print a ++ print b\n\njoin :: a [b] -> [String] | print a & print b\njoin _ [] = []\njoin a [b:[]] = print b\njoin a [b:bs] = b <+ a <+ join a bs\n\nalignl :: Int a -> [String] | print a\nalignl i s\n# s = print s\n# len = sum (map size s)\n| len >= i = s\n| otherwise = s ++ [{' ' \\\\ i <- [0..i-len]}]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","old_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\n\n\/\/ StdEnv\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nfrom Text import class Text(concat), instance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String\nimport CoclUtils\n\n\/\/ frontend\n\/\/import Heap, compile, parse, predef\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents), ::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr, ::Position(NoPos), ::Module{mod_ident,mod_defs}, ::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class), ::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType, ::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_types}, ::Type, ::ClassDef{class_ident,class_args}, ::TypeVar\nfrom parse import wantModule\n\n:: CLI = {\n\thelp :: Bool,\n\tversion :: Bool,\n\troot :: String,\n\tlibs :: [String]}\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ \"StdEnv\"\n\t , \"StdLib\"\n\t , \"ArgEnv\"\n\t , \"Directory\"\n\t , \"Dynamics\"\n\t , \"Gast\"\n\t , \"Generics\"\n\t , \"MersenneTwister\"\n\t , \"TCPIP\"\n\t , \"clean-platform\/OS-Independent\"\n\t , \"clean-platform\/OS-Linux\"\n\t , \"clean-platform\/OS-Linux-32\"\n\t , \"clean-platform\/OS-Linux-64\"\n\t , \"clean-platform\/OS-Mac\"\n\t , \"clean-platform\/OS-Posix\"\n\t , \"clean-platform\/OS-Windows\"\n\t , \"clean-platform\/OS-Windows-32\"\n\t , \"clean-platform\/OS-Windows-64\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > builddb.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (mods, w) = findModules` cli.libs cli.root w\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop mods 'DB'.newDb cache w\n\t# f = 'DB'.saveDb db f\n\t= fclose f w\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: [(String,String)] 'DB'.TypeDB *DclCache *World -> *('DB'.TypeDB, *World)\n\tloop [] db _ w = (db,w)\n\tloop [(lib,mod):list] db cache w\n\t# (db, cache, w) = getModuleTypes mod lib cache db w\n\t\/\/# db = 'DB'.putTypes sts db\n\t= loop list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[x:c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\/\/ Libraries Library Module\nfindModules` :: ![String] !String !*World -> *(![(String,String)], !*World)\nfindModules` [] _ w = ([], w)\nfindModules` [lib:libs] root w\n#! (mods, w) = findModules lib root w\n#! (moremods, w) = findModules` libs root w\n= (removeDup (mods ++ moremods), w)\n\nfindModules :: !String !String !*World -> *(![(String,String)], !*World)\nfindModules lib root w\n#! (fps, w) = readDirectory (root +++ \"\/\" +++ lib) w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (tuple (root +++ lib)) $ map (\\s->s%(0,size s-5)) $ filter isDclModule fps\n#! (moremods, w) = findModules` (map ((+++) (lib+++\"\/\")) (filter isDirectory fps)) root w\n= (removeDup (mods ++ moremods), w)\nwhere\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\" && s.[0] <> '_'\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String String *DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes mod lib cache db w\n# filename = lib +++ \"\/\" +++ mkdir mod +++ \".dcl\"\n# (ok,f,w) = fopen filename FReadText w\n| not ok = abort (\"Couldn't open file \" +++ filename +++ \".\\n\")\n# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n cache = {cache & hash_table=ht}\n# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" False mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n cache = {cache & hash_table=ht}\n# (ok,w) = fclose f w\n| not ok = abort (\"Couldn't close file \" +++ filename +++ \".\\n\")\n# mod = pm.mod_ident.id_name\n# db = 'DB'.putTypes (pd_typespecs mod pm.mod_defs) db\n# db = 'DB'.putInstancess (pd_instances mod pm.mod_defs) db\n# db = 'DB'.putClasses (pd_classes mod pm.mod_defs) db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = {if (c == '.') '\/' c\\\\c<-:s}\n\n\tpd_typespecs :: String [ParsedDefinition] -> [('DB'.FunctionLocation, 'DB'.Type)]\n\tpd_typespecs mod pds\n\t# pds = filter (\\pd->case pd of (PD_TypeSpec _ _ _ _ _)=True; _=False) pds\n\t# sts = map (\\(PD_TypeSpec pos id prio st funspecs) -> ('DB'.FL lib mod id.id_name,st)) pds\n\t# sts = filter (\\st->case st of (_,(Yes _))=True; _=False) sts\n\t# sts = map (\\(loc,Yes x)->(loc,'T'.toType x)) sts\n\t= sts\n\n\tpd_instances :: String [ParsedDefinition] -> [('DB'.Class, ['DB'.Type])]\n\tpd_instances mod pds\n\t# pds = filter (\\pd->case pd of (PD_Instance _)=True; _=False) pds\n\t= map (\\(PD_Instance {pim_pi={pi_ident,pi_types}})\n\t\t-> (pi_ident.id_name, map 'T'.toType pi_types)) pds\n\n\tpd_classes :: String [ParsedDefinition]\n\t\t-> [('DB'.ClassLocation, ['T'.TypeVar], [('DB'.FunctionName, 'T'.Type)])]\n\tpd_classes mod pds\n\t# pds = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) pds\n\t= map (\\(PD_Class {class_ident={id_name},class_args} pds)\n\t\t-> let typespecs = pd_typespecs mod pds\n\t\tin ('DB'.CL lib mod id_name, map 'T'.toTypeVar class_args, \n\t\t\t[(f,t) \\\\ ('DB'.FL _ _ f, t) <- typespecs])) pds\n\nunigroups :: (Type Type -> Bool) [(a,Type)] -> [([a],Type)]\nunigroups f ts = unigroups` ts []\nwhere\n\tunigroups` [] groups = groups\n\tunigroups` [(a,t):ts] [] = unigroups` ts [([a],t)]\n\tunigroups` [(a,t):ts] [(ns,ut):groups]\n\t| f t ut\t= unigroups` ts [([a:ns],ut):groups]\n\t| otherwise = unigroups` ts [(ns,ut):unigroups` [(a,t)] groups]\n\n(<+) infixr 5 :: a b -> [String] | print a & print b\n(<+) a b = print a ++ print b\n\njoin :: a [b] -> [String] | print a & print b\njoin _ [] = []\njoin a [b:[]] = print b\njoin a [b:bs] = b <+ a <+ join a bs\n\nalignl :: Int a -> [String] | print a\nalignl i s\n# s = print s\n# len = sum (map size s)\n| len >= i = s\n| otherwise = s ++ [{' ' \\\\ i <- [0..i-len]}]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"4d20af9d3ba3be78e94032e816803a95e4dbdf80","subject":"*** empty log message ***","message":"*** empty log message ***\n","repos":"kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout,kragen\/shootout","old_file":"bench\/binarytrees\/binarytrees.icl","new_file":"bench\/binarytrees\/binarytrees.icl","new_contents":"\/* The Great Computer Language Shootout\n http:\/\/shootout.alioth.debian.org\/\n\n contributed by Isaac Gouy (Clean novice)\n*\/\n\nmodule binarytrees\nimport StdEnv, LanguageShootout\n\nStart world\n\t# max` = max (min`+2) argi\n\t# stretch` = max` + 1\n\t# (io,world) = stdio world\n\t#! io = showItemCheck stretch` (bottomup 0 stretch`) \"stretch tree of depth \" io\n\t#! longLived = bottomup 0 max`\n\t#! io = depthloop min` max` io\n\t#! io = showItemCheck max` longLived \"long lived tree of depth \" io\t\t\n\t# (error,world) = fclose io world\n\t= world\t\t\n\t\nmin` = 4\t\n\t\nshowItemCheck d a s io\n\t= io <<< s <<< toString (d) <<<\n\t\t\"\\t check: \" <<< toString (itemcheck a) <<< \"\\n\"\t\n\t\t\nshowCheck i d check io\n\t= io <<< toString (2*i) <<< \"\\t trees of depth \" <<< \n\t\ttoString (d) <<< \"\\t check: \" <<< toString (check) <<< \"\\n\"\t\t\t\t\t\t\n\t\t\t\t\ndepthloop d m io\n\t| d > m = io\n = depthloop (d+2) m (showCheck n d check io)\t\n\twhere \n\t\tn = 1 << (m - d + min`)\n\t\tcheck = sumloop n d 0\t\n\nsumloop :: !Int !Int !Int -> Int\t\nsumloop n d sum\n\t| n > 0\t= sumloop (n-1) d (sum + check + check`)\t\n\t= sum\n\twhere \n\t check = itemcheck (bottomup n d)\n\t check` = itemcheck (bottomup (-1*n) d)\t \n\n\n:: Tree a = TreeNode a (Tree a) (Tree a) | Nil\n\nbottomup :: !Int !Int -> .(Tree Int)\nbottomup i d\n\t| d < 0 = Nil\t\t\t\n\t\t\t= TreeNode i (bottomup (2*i-1)(d-1)) (bottomup (2*i)(d-1))\t\n\nitemcheck Nil = 0\nitemcheck (TreeNode a left right) = a + itemcheck(left) - itemcheck(right)\t\t\t\t\t","old_contents":"module binarytrees\nimport StdEnv\n\nStart world\n\t# max` = max (min`+2) 20\n\t# stretch` = max` + 1\n\t# (io,world) = stdio world\n\t#! io = showItemCheck stretch` (bottomup 0 stretch`) \"stretch tree of depth \" io\n\t#! longLived = bottomup 0 max`\n\t#! io = depthloop min` max` io\n\t#! io = showItemCheck max` longLived \"long lived tree of depth \" io\t\t\n\t# (error,world) = fclose io world\n\t= world\t\t\n\t\nmin` = 4\t\n\t\nshowItemCheck d a s io\n\t= io <<< s <<< toString (d) <<<\n\t\t\"\\t check: \" <<< toString (itemcheck a) <<< \"\\n\"\t\n\t\t\nshowCheck i d check io\n\t= io <<< toString (2*i) <<< \"\\t trees of depth \" <<< \n\t\ttoString (d) <<< \"\\t check: \" <<< toString (check) <<< \"\\n\"\t\t\t\t\t\t\n\t\t\t\t\ndepthloop d m io\n\t| d > m = io\n = depthloop (d+2) m (showCheck n d check io)\t\n\twhere \n\t\tn = 1 << (m - d + min`)\n\t\tcheck = sumloop n d 0\t\n\nsumloop :: !Int !Int !Int -> Int\t\nsumloop n d sum\n\t| n > 0\t= sumloop (n-1) d (sum + check + check`)\t\n\t= sum\n\twhere \n\t check = itemcheck (bottomup n d)\n\t check` = itemcheck (bottomup (-1*n) d)\t \n\n\n:: Tree a = TreeNode a (Tree a) (Tree a) | Nil\n\nbottomup :: !Int !Int -> .(Tree Int)\nbottomup i d\n\t| d < 0 = Nil\t\t\t\n\t\t\t= TreeNode i (bottomup (2*i-1)(d-1)) (bottomup (2*i)(d-1))\t\n\nitemcheck Nil = 0\nitemcheck (TreeNode a left right) = a + itemcheck(left) - itemcheck(right)\t\t\t\t\t","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Clean"} {"commit":"4d7fa14dd1ce3f1f87bf991d17dd017917131f4a","subject":"Fork that reloads cache should not continue handling requests afterwards","message":"Fork that reloads cache should not continue handling requests afterwards\n","repos":"dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o, seq\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable, instance Foldable Maybe\nfrom Data.Func import $, hyperstrict\nimport Data.Functor\nimport Data.List\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_include_apps = fromJust (r.include_apps <|> Just DEFAULT_INCLUDE_APPS)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDb f\n#! db = hyperstrict db\n#! w = if opts.reload_cache (doInBackground (reloadCache db)) id w\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle db\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !CloogleDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle db Nothing w = (err InvalidInput \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond {r & return = if (r.return == 0) 1 r.return} w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err InvalidName \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err InvalidName \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err InvalidType \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! results = drop drop_n $ sort $ search request db\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! suggestions = unify >>= parseType o fromString >>= flip (suggs name) db\n\t\t#! w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- 'Foldable'.concat suggestions] w\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: !Response !*World -> *(!Response, !CacheKey, !*World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !CloogleDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\treloadCache :: !CloogleDB -> *World -> *World\n\treloadCache db = uncurry (flip (foldl (flip search))) o allCacheKeys LongTerm\n\twhere\n\t\tsearch :: !RequestCacheKey -> *World -> *World\n\t\tsearch r = thd3 o handle db (Just $ fromRequestCacheKey r) o removeFromCache LongTerm r\n\n\tdoInBackground :: (*World -> *World) *World -> *World\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o, seq\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable, instance Foldable Maybe\nfrom Data.Func import $, hyperstrict\nimport Data.Functor\nimport Data.List\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_include_apps = fromJust (r.include_apps <|> Just DEFAULT_INCLUDE_APPS)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDb f\n#! db = hyperstrict db\n#! w = if opts.reload_cache (doInBackground (reloadCache db)) id w\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle db\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !CloogleDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle db Nothing w = (err InvalidInput \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond {r & return = if (r.return == 0) 1 r.return} w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err InvalidName \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err InvalidName \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err InvalidType \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! results = drop drop_n $ sort $ search request db\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! suggestions = unify >>= parseType o fromString >>= flip (suggs name) db\n\t\t#! w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- 'Foldable'.concat suggestions] w\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: !Response !*World -> *(!Response, !CacheKey, !*World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !CloogleDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\treloadCache :: !CloogleDB -> *World -> *World\n\treloadCache db = uncurry (flip (foldl (flip search))) o allCacheKeys LongTerm\n\twhere\n\t\tsearch :: !RequestCacheKey -> *World -> *World\n\t\tsearch r = thd3 o handle db (Just $ fromRequestCacheKey r) o removeFromCache LongTerm r\n\n\tdoInBackground :: (*World -> *World) *World -> *World\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"e23f2e93d8482c278972b212a0f9cab287476810","subject":"Add ^ for overloaded type variables in dynamic pattern matches","message":"Add ^ for overloaded type variables in dynamic pattern matches\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/Builtins.icl","new_file":"backend\/Builtins.icl","new_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [(Location, FunctionEntry)]\nbuiltin_functions\n\t= [ ( Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , {zero & fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []}\n\t )\n\t , ( Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , {zero & fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]}\n\t )\n\t ]\n\nbuiltin_classes :: [(Location, ClassEntry)]\nbuiltin_classes\n\t= [ ( Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , { ce_vars=[\"v\"]\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t }\n\t )\n\t ]\n\nbuiltin_types :: [(Location, TypeDefEntry)]\nbuiltin_types\n\t= [ ( Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , { deft\n\t & tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Int\"})\n\t , ( Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Real\"})\n\t , ( Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Char\"})\n\t , ( Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"String\",\n\t tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], {deft & tde_typedef.td_name = \"Dynamic\"})\n\t , ( Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"File\"})\n\t , ( Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"World\",\n\t tde_typedef.td_uniq = True,\n\t tde_doc = Just $ TypeDoc\n\t (Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\")\n\t [] Nothing})\n\t , ( Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"], {deft & tde_typedef.td_name = \"(->)\",\n\t tde_typedef.td_args = [Var \"a\", Var \"b\"],\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\")\n\t [\"The argument type\", \"The result type\"]\n\t Nothing})\n\t , ( Builtin \"()\" [], {deft & tde_typedef.td_name=\"_Unit\",\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The void \/ unit type.\")\n\t [] Nothing,\n\t tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]})\n\t : lists\n\t ++ arrays\n\t ++ tuples\n\t ]\nwhere\n\tdeft = {tde_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract Nothing}, tde_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> (Location, TypeDefEntry)\n\t\tmake_list k s = (Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description)\n\t\t\t\t[\"The type of the list elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> (Location, TypeDefEntry)\n\t\tmake_array k = (Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description)\n\t\t\t\t[\"The type of the array elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> (Location, TypeDefEntry)\n\t\tmake_tuple n = (Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t \"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t \"Clean supports tuples of arity 2 to 32.\")\n\t\t\t\t[] Nothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_class = ([\"class\"],\n\t{ syntax_title = \"class\"\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t})\n\nbs_code = ([\"code\", \"inline\", \"code inline\"],\n\t{ syntax_title = \"ABC code\"\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t})\n\nbs_generic = ([\"generic\", \"derive\", \"of\", \"{|*|}\"], \/\/ This * matches everything, which is intentional\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_instance = ([\"instance\"],\n\t{ syntax_title = \"instance\"\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t})\n\nbs_lambda = ([\"lambda\", \"\\\\*\", \"->\", \".\"],\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t})\n\nbs_layout_rule = ([\";\", \"{\", \"}\"],\n\t{ syntax_title = \"layout rule\"\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_list_expressions = ([\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"],\n\t{ syntax_title = \"list expression\"\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t})\n\nbs_macro = ([\":==\", \"macro\"],\n\t{ syntax_title = \"macro\"\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t})\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_newtype = ([\"=:\", \"newtype\"],\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t})\n\nbs_overloaded_type_variable = ([\"^\", \"a^\"],\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t})\n\nbs_selection_array = ([\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"],\n\t{ syntax_title = \"array selection\"\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t})\nbs_selection_array_unique = ([\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"],\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t})\nbs_selection_record = ([\".\"],\n\t{ syntax_title = \"record selection\"\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t})\nbs_selection_record_unique = ([\"!\"],\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n\nbs_zf = ([\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"],\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t})\n","old_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [(Location, FunctionEntry)]\nbuiltin_functions\n\t= [ ( Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , {zero & fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []}\n\t )\n\t , ( Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , {zero & fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]}\n\t )\n\t ]\n\nbuiltin_classes :: [(Location, ClassEntry)]\nbuiltin_classes\n\t= [ ( Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , { ce_vars=[\"v\"]\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t }\n\t )\n\t ]\n\nbuiltin_types :: [(Location, TypeDefEntry)]\nbuiltin_types\n\t= [ ( Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , { deft\n\t & tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Int\"})\n\t , ( Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Real\"})\n\t , ( Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Char\"})\n\t , ( Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"String\",\n\t tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], {deft & tde_typedef.td_name = \"Dynamic\"})\n\t , ( Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"File\"})\n\t , ( Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"World\",\n\t tde_typedef.td_uniq = True,\n\t tde_doc = Just $ TypeDoc\n\t (Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\")\n\t [] Nothing})\n\t , ( Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"], {deft & tde_typedef.td_name = \"(->)\",\n\t tde_typedef.td_args = [Var \"a\", Var \"b\"],\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\")\n\t [\"The argument type\", \"The result type\"]\n\t Nothing})\n\t , ( Builtin \"()\" [], {deft & tde_typedef.td_name=\"_Unit\",\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The void \/ unit type.\")\n\t [] Nothing,\n\t tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]})\n\t : lists\n\t ++ arrays\n\t ++ tuples\n\t ]\nwhere\n\tdeft = {tde_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract Nothing}, tde_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> (Location, TypeDefEntry)\n\t\tmake_list k s = (Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description)\n\t\t\t\t[\"The type of the list elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> (Location, TypeDefEntry)\n\t\tmake_array k = (Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description)\n\t\t\t\t[\"The type of the array elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> (Location, TypeDefEntry)\n\t\tmake_tuple n = (Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t \"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t \"Clean supports tuples of arity 2 to 32.\")\n\t\t\t\t[] Nothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_class = ([\"class\"],\n\t{ syntax_title = \"class\"\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t})\n\nbs_code = ([\"code\", \"inline\", \"code inline\"],\n\t{ syntax_title = \"ABC code\"\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t})\n\nbs_generic = ([\"generic\", \"derive\", \"of\", \"{|*|}\"], \/\/ This * matches everything, which is intentional\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_instance = ([\"instance\"],\n\t{ syntax_title = \"instance\"\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t})\n\nbs_lambda = ([\"lambda\", \"\\\\*\", \"->\", \".\"],\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t})\n\nbs_layout_rule = ([\";\", \"{\", \"}\"],\n\t{ syntax_title = \"layout rule\"\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_list_expressions = ([\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"],\n\t{ syntax_title = \"list expression\"\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t})\n\nbs_macro = ([\":==\", \"macro\"],\n\t{ syntax_title = \"macro\"\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t})\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_newtype = ([\"=:\", \"newtype\"],\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t})\n\nbs_selection_array = ([\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"],\n\t{ syntax_title = \"array selection\"\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t})\nbs_selection_array_unique = ([\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"],\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t})\nbs_selection_record = ([\".\"],\n\t{ syntax_title = \"record selection\"\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t})\nbs_selection_record_unique = ([\"!\"],\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n\nbs_zf = ([\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"],\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t})\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"8597aad03f39c3a4c0cd65bf13574e3a81c790b1","subject":"Fix uniqueness documentation","message":"Fix uniqueness documentation\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \".\", \"%:\", \"[*<=*]\", \",\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parenthesis when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \".\", \"%:\", \"[*<=*]\", \",\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:... | [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [...<=...]`).\"\n\t\t, \"\\n\\nNote that when using unique types in a function or an ADT the container must also be unique.\"\n\t\t, \"For instance, `T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"\\n\\nFunctions have to be split up into arity 1 and the sub functions need to be annotated as well.\"\n\t\t, \"For instance, `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parenthesis when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"77edb91052d73e4f17981ba13d5128188ad0816c","subject":"Fix Pattern match miss in Bot parsing","message":"Fix Pattern match miss in Bot parsing\n","repos":"ErinvanderVeen\/Clone,ErinvanderVeen\/Clone","old_file":"src\/Config.icl","new_file":"src\/Config.icl","new_contents":"implementation module Config\n\nimport Bot\nimport System.File, Text.JSON, Data.Maybe\nfrom Data.Error import isError, fromOk\nfrom StdMisc import abort\nfrom StdFile import instance FileSystem World\nfrom StdFunc import o\n\nparseConfig :: !*World -> (Config, *World)\nparseConfig w\n# (configString, w) = readConfig w\n# node = fromString configString\n# botsArray = jsonQuery \"bots\" node\n| isNothing botsArray = abort \"Could not find \\\"bots\\\" in config file\"\n# botsArray = fromJSONArray (fromJust botsArray)\n| isNothing botsArray = abort \"Could not get bots array from config file\"\n# botsArray = map toBot (fromJust botsArray)\n# config = { Config | bots = botsArray }\n= (config, w)\nwhere\n\treadConfig :: !*World -> (String, *World)\n\treadConfig w\n\t# (result, w) = readFile \"config.json\" w\n\t| isError result = abort \"Could not read from config file\"\n\t# result = fromOk result\n\t= (result, w)\n\nfromJSONArray :: JSONNode -> Maybe [JSONNode]\nfromJSONArray (JSONArray x) = Just x\nfromJSONArray _ = Nothing\n\nfromJSONObject :: JSONNode -> [(!String, !JSONNode)]\nfromJSONObject (JSONObject x) = x\nfromJSONObject _ = abort \"Could not retrieve JSONObject\"\n\ntoBot :: JSONNode -> Bot\ntoBot node=:(JSONObject _) =\n\t\t{Bot |\n\t\t\tname = fromJust (jsonQuery \"name\" node),\n\t\t\texe = fromJust (jsonQuery \"exe\" node),\n\t\t\tvars = fromMaybe [] (jsonQuery \"vars\" node),\n\t\t\tinterval = fromJust (jsonQuery \"interval\" node),\n\t\t\tchildren = fromMaybe [] (jsonQuery \"children\" node),\n\t\t\troot = fromMaybe False (jsonQuery \"root\" node)\n\t\t}\ntoBot _ = abort \"Could not parse bot in config file\"\n","old_contents":"implementation module Config\n\nimport Bot\nimport System.File, Text.JSON, Data.Maybe\nfrom Data.Error import isError, fromOk\nfrom StdMisc import abort\nfrom StdFile import instance FileSystem World\nfrom StdFunc import o\n\nparseConfig :: !*World -> (Config, *World)\nparseConfig w\n# (configString, w) = readConfig w\n# node = fromString configString\n# botsArray = jsonQuery \"bots\" node\n| isNothing botsArray = abort \"Could not find \\\"bots\\\" in config file\"\n# botsArray = fromJSONArray (fromJust botsArray)\n| isNothing botsArray = abort \"Could not get bots array from config file\"\n# botsArray = map toBot (fromJust botsArray)\n# config = { Config | bots = botsArray }\n= (config, w)\nwhere\n\treadConfig :: !*World -> (String, *World)\n\treadConfig w\n\t# (result, w) = readFile \"config.json\" w\n\t| isError result = abort \"Could not read from config file\"\n\t# result = fromOk result\n\t= (result, w)\n\nfromJSONArray :: JSONNode -> Maybe [JSONNode]\nfromJSONArray (JSONArray x) = Just x\nfromJSONArray _ = Nothing\n\nfromJSONObject :: JSONNode -> [(!String, !JSONNode)]\nfromJSONObject (JSONObject x) = x\nfromJSONObject _ = abort \"Could not retrieve JSONObject\"\n\ntoBot :: JSONNode -> Bot\ntoBot node=:(JSONObject _) =\n\t\t{Bot |\n\t\t\tname = fromJust (jsonQuery \"name\" node),\n\t\t\texe = fromJust (jsonQuery \"exe\" node),\n\t\t\tvars = fromJust (jsonQuery \"vars\" node),\n\t\t\tinterval = fromJust (jsonQuery \"interval\" node),\n\t\t\tchildren = fromJust (jsonQuery \"children\" node),\n\t\t\troot = fromJust (jsonQuery \"root\" node)\n\t\t}\ntoBot _ = abort \"Could not parse bot in config file\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"c1e594066f2c4b405888c9b6478f9ced626be618","subject":"Improved logging; fit CloogleServer in 80 chars","message":"Improved logging; fit CloogleServer in 80 chars\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"CloogleServer.icl","new_file":"CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdEnv\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.Maybe\nimport System.CommandLine\nimport Text\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nfrom Control.Monad import class Monad(..)\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Command = { unify :: String\n , name :: String\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n }\n\n:: Result = { library :: String\n , filename :: String\n , func :: String\n , cls :: Maybe ClassResult\n , modul :: String\n , distance :: Int\n }\n\n:: ErrorResult = Error Int String\n\n:: ClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Command, Response, Result, ClassResult\nderive JSONDecode Command, Response, Result, ClassResult\n\ninstance toString Response where toString r = toString $ toJSON r\ninstance toString Command where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Command) where fromString s = fromJSON $ fromString s\n\ninstance < Result where (<) r1 r2 = r1.distance < r2.distance\n\nerr :: Int String -> Response\nerr c m = {return=c, data=[], msg=m}\n\nMAX_RESULTS :== 100\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n# db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: TypeDB (Maybe Command) *World -> *(Response, *World)\n\thandle _ Nothing w = (err 4 \"Couldn't parse input\", w)\n\thandle db (Just {unify,name}) w\n\t\t# mbType = parseType (fromString unify)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes $ [ (\\t->(\\_ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\loc _ ->\n\t\t isNameMatch (size name-2) name loc)\n\t\t ]\n\t\t# funcs = map (makeResult name mbType Nothing) $ findType`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes $ [ (\\t->(\\_ _ _ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\(CL lib mod _) _ f _ ->\n\t\t isNameMatch (size name-2) name (FL lib mod f))\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,f,t) -> makeResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,t)) members\n\t\t# results = take MAX_RESULTS $ sort $ funcs ++ members\n\t\t= ({return=0,msg=\"Success\",data=results}, w)\n\n\tmakeResult :: String (Maybe Type) (Maybe ClassResult)\n\t (FunctionLocation, Type) -> Result\n\tmakeResult orgsearch orgsearchtype mbCls (FL lib mod fname, type)\n\t\t= { library = lib\n\t\t , filename = (toString $ reverse $ takeWhile ((<>)'.')\n\t\t $ reverse $ fromString mod) +++ \".dcl\"\n\t\t , modul = mod\n\t\t , func = fname +++ \" :: \" +++ concat (stripParens $ print type)\n\t\t , cls = mbCls\n\t\t , distance = distance\n\t\t }\n\twhere\n\t\tstripParens :: [String] -> [String]\n\t\tstripParens [\"(\":ss]\n\t\t\t| last ss == \")\" && parensMatch 0 (init ss) = stripParens $ init ss\n\t\t\t| otherwise = [\"(\":ss]\n\t\tstripParens ss = ss\n\n\t\tparensMatch :: Int [String] -> Bool\n\t\tparensMatch 0 [] = True\n\t\tparensMatch _ [] = False\n\t\tparensMatch i [\"(\":ss] = i >= 0 && parensMatch (i+1) ss\n\t\tparensMatch i [\")\":ss] = i >= 0 && parensMatch (i-1) ss\n\t\tparensMatch i [_:ss] = i >= 0 && parensMatch i ss\n\n\t\tdistance\n\t\t\t| orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = unify [] orgsearchtype type\n\t\t\t\t= length $ filter (not o isVar o snd) $ ass1 ++ ass2\n\t\t\t# levdist = levenshtein fname orgsearch\n\t\t\t= if (indexOf orgsearch fname == -1) 0 -100 + levdist\n\n\tisUnifiable :: Type Type -> Bool\n\tisUnifiable t1 t2 = isJust (unify [] t1 t2)\n\n\tisNameMatch :: Int String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tlog :: (LogMessage (Maybe Command) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t# (io,w) = stdio w\n\t# io = fwrites (msgToString msg s) io\n\t= (newS msg s, snd (fclose io w))\n\n\tnewS :: (LogMessage (Maybe Command) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Command) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent {return,data,msg}) ip\n\t\t= toString ip +++ \" --> \" +++ toString (length data) +++ \" results (\"\n\t\t\t+++ toString return +++ \"; \" +++ msg +++ \")\\n\"\n\tmsgToString _ _ = \"\"\n\n","old_contents":"module CloogleServer\n\nimport StdString, StdArray, StdList, StdFile, StdTuple, StdMisc, StdOrdList, StdBool\nfrom StdFunc import o\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.Maybe\nimport System.CommandLine\nimport Text\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nfrom Control.Monad import class Monad(..)\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Command = { unify :: String\n , name :: String\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n }\n\n:: Result = { library :: String\n , filename :: String\n , func :: String\n , cls :: Maybe ClassResult\n , modul :: String\n , distance :: Int\n }\n\n:: ErrorResult = Error Int String\n\n:: ClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Command, Response, Result, ClassResult\nderive JSONDecode Command, Response, Result, ClassResult\n\ninstance toString Response where toString r = toString $ toJSON r\ninstance toString Command where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Command) where fromString s = fromJSON $ fromString s\n\ninstance < Result where (<) r1 r2 = r1.distance < r2.distance\n\nerr :: Int String -> Response\nerr c m = {return=c, data=[], msg=m}\n\nMAX_RESULTS :== 100\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n# db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: TypeDB (Maybe Command) *World -> *(Response, *World)\n\thandle _ Nothing w = (err 4 \"Couldn't parse input\", w)\n\thandle db (Just {unify,name}) w\n\t\t# mbType = parseType (fromString unify)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes $ [ (\\t->(\\_ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\loc _ ->\n\t\t isNameMatch (size name - 2) name loc)\n\t\t ]\n\t\t# funcs = map (makeResult name mbType Nothing) $ findType`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes $ [ (\\t->(\\_ _ _ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\(CL lib mod _) _ f _ ->\n\t\t isNameMatch (size name - 2) name (FL lib mod f))\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,f,t) -> makeResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,t)) members\n\t\t# results = take MAX_RESULTS $ sort $ funcs ++ members\n\t\t= ({return=0,msg=\"Success\",data=results}, w)\n\n\tmakeResult :: String (Maybe Type) (Maybe ClassResult) (FunctionLocation, Type) -> Result\n\tmakeResult orgsearch orgsearchtype mbCls (FL lib mod fname, type)\n\t\t= { library = lib\n\t\t , filename = (toString $ reverse $ takeWhile ((<>)'.') $ reverse $ fromString mod) +++ \".dcl\"\n\t\t , modul = mod\n\t\t , func = fname +++ \" :: \" +++ concat (stripParens $ print type)\n\t\t , cls = mbCls\n\t\t , distance = distance\n\t\t }\n\twhere\n\t\tstripParens :: [String] -> [String]\n\t\tstripParens [\"(\":ss]\n\t\t\t| last ss == \")\" && parensMatch 0 (init ss) = stripParens $ init ss\n\t\t\t| otherwise = [\"(\":ss]\n\t\tstripParens ss = ss\n\n\t\tparensMatch :: Int [String] -> Bool\n\t\tparensMatch 0 [] = True\n\t\tparensMatch _ [] = False\n\t\tparensMatch i [\"(\":ss] = i >= 0 && parensMatch (i+1) ss\n\t\tparensMatch i [\")\":ss] = i >= 0 && parensMatch (i-1) ss\n\t\tparensMatch i [_:ss] = i >= 0 && parensMatch i ss\n\n\t\tdistance\n\t\t\t| orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = unify [] orgsearchtype type\n\t\t\t\t= length $ filter (not o isVar o snd) $ ass1 ++ ass2\n\t\t\t# levdist = levenshtein fname orgsearch\n\t\t\t= if (indexOf orgsearch fname == -1) 0 -100 + levdist\n\n\tisUnifiable :: Type Type -> Bool\n\tisUnifiable t1 t2 = isJust (unify [] t1 t2)\n\n\tisNameMatch :: Int String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tlog :: (LogMessage (Maybe Command) Response) IPAddress *World -> *(IPAddress, *World)\n\tlog msg s w\n\t# (io,w) = stdio w\n\t# io = fwrites (msgToString msg s) io\n\t= (newS msg s, snd (fclose io w))\n\n\tnewS :: (LogMessage (Maybe Command) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Command) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent b) ip\n\t\t= toString ip +++ \" --> \" +++ toString b +++ \"\\n\"\n\tmsgToString _ _ = \"\"\n\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"dec1329d2ac7ecac4f50f54f5461124d93dbb3a8","subject":"Fix cache reloading","message":"Fix cache reloading\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat,toLowerCase), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\nCACHE_NS_THRESHOLD :== 40000000\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Maybe [String]\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (alwaysUnique,db) = alwaysUniquePredicate db\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True alwaysUnique allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> unprepare <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\nwhere\n\tunprepare :: !Type -> Type\n\tunprepare (Type t ts) = Type t (map unprepare ts)\n\tunprepare (Func is t tc) = Func (map unprepare is) (unprepare t) (map unprepareTR tc)\n\tunprepare (Var tv) = Var (tv % (1,size tv-1))\n\tunprepare (Cons v ts) = Cons (v % (1,size v-1)) (map unprepare ts)\n\tunprepare (Uniq t) = Uniq (unprepare t)\n\tunprepare (Forall ts t tc) = Forall (map unprepare ts) (unprepare t) (map unprepareTR tc)\n\tunprepare (Arrow mt) = Arrow (unprepare <$> mt)\n\n\tunprepareTR :: !TypeRestriction -> TypeRestriction\n\tunprepareTR (Instance c ts) = Instance c (map unprepare ts)\n\tunprepareTR (Derivation g t) = Derivation g (unprepare t)\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w)\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", (Nothing,0), db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t#! (start,w) = nsTime w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond start Nothing {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond start Nothing (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond start Nothing (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond start Nothing (err InvalidType \"Couldn't parse type\") db w\n\t\t| all isNothing [unify,name,request.typeName,request.className] && isNothing request.using\n\t\t\t= respond start Nothing (err InvalidInput \"Empty query\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond start (Just key) response db w\n\twhere\n\t\trespond :: !Timespec !(Maybe RequestCacheKey) !Response !*CloogleDB !*World ->\n\t\t\t*(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\t\trespond start key r db w\n\t\t#! (end,w) = nsTime w\n\t\t#! duration = 1000000000 * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec\n\t\t#! cache = duration > CACHE_NS_THRESHOLD\n\t\t= (r, (if cache (cacheKey <$> key) Nothing, duration \/ 1000), db, case (cache,key) of\n\t\t\t(True,Just k) -> writeCache LongTerm k r w\n\t\t\t_ -> w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World)\n\treloadCache (db,w)\n\t# (ks,w) = allCacheKeys LongTerm w\n\t= loop ks db w\n\twhere\n\t\tloop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World)\n\t\tloop [] db w = (db,w)\n\t\tloop [k:ks] db w\n\t\t# w = removeFromCache LongTerm k w\n\t\t# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w\n\t\t# db = resetDB db\n\t\t= loop ks db w\n\n\tdoInBackground :: (*a -> *a) *a -> *a\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: MicroSeconds :== Int\n\n:: LogMessage` :== LogMessage (Maybe Request) Response (Maybe CacheKey, MicroSeconds)\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, microseconds :: Int\n\t, request :: Maybe Request\n\t, cachekey :: Maybe String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response (ck,us)) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, microseconds = us\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat,toLowerCase), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\nCACHE_NS_THRESHOLD :== 40000000\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Maybe [String]\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (alwaysUnique,db) = alwaysUniquePredicate db\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True alwaysUnique allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w)\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", (Nothing,0), db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t#! (start,w) = nsTime w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond start Nothing {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond start Nothing (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond start Nothing (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond start Nothing (err InvalidType \"Couldn't parse type\") db w\n\t\t| all isNothing [unify,name,request.typeName,request.className] && isNothing request.using\n\t\t\t= respond start Nothing (err InvalidInput \"Empty query\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond start (Just key) response db w\n\twhere\n\t\trespond :: !Timespec !(Maybe RequestCacheKey) !Response !*CloogleDB !*World ->\n\t\t\t*(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\t\trespond start key r db w\n\t\t#! (end,w) = nsTime w\n\t\t#! duration = 1000000000 * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec\n\t\t#! cache = duration > CACHE_NS_THRESHOLD\n\t\t= (r, (if cache (cacheKey <$> key) Nothing, duration \/ 1000), db, case (cache,key) of\n\t\t\t(True,Just k) -> writeCache LongTerm k r w\n\t\t\t_ -> w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World)\n\treloadCache (db,w)\n\t# (ks,w) = allCacheKeys LongTerm w\n\t= loop ks db w\n\twhere\n\t\tloop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World)\n\t\tloop [] db w = (db,w)\n\t\tloop [k:ks] db w\n\t\t# w = removeFromCache LongTerm k w\n\t\t# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w\n\t\t# db = resetDB db\n\t\t= loop ks db w\n\n\tdoInBackground :: (*a -> *a) *a -> *a\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: MicroSeconds :== Int\n\n:: LogMessage` :== LogMessage (Maybe Request) Response (Maybe CacheKey, MicroSeconds)\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, microseconds :: Int\n\t, request :: Maybe Request\n\t, cachekey :: Maybe String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response (ck,us)) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, microseconds = us\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"9a4f5d4be0288d5629567bbf578780335897c747","subject":"Indentation","message":"Indentation\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"builddb.icl","new_file":"builddb.icl","new_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\n\n\/\/ StdEnv\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nfrom Text import class Text(concat), instance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String\nimport CoclUtils\n\n\/\/ frontend\n\/\/import Heap, compile, parse, predef\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents), ::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr, ::Position(NoPos), ::Module{mod_ident,mod_defs}, ::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class), ::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType, ::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_types}, ::Type, ::ClassDef{class_ident,class_args}, ::TypeVar\nfrom parse import wantModule\n\n:: CLI = {\n\thelp :: Bool,\n\tversion :: Bool,\n\troot :: String,\n\tlibs :: [String]}\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ \"StdEnv\"\n\t , \"StdLib\"\n\t , \"ArgEnv\"\n\t , \"Directory\"\n\t , \"Dynamics\"\n\t , \"Gast\"\n\t , \"Generics\"\n\t , \"MersenneTwister\"\n\t , \"TCPIP\"\n\t , \"clean-platform\/OS-Independent\"\n\t , \"clean-platform\/OS-Linux\"\n\t , \"clean-platform\/OS-Linux-32\"\n\t , \"clean-platform\/OS-Linux-64\"\n\t , \"clean-platform\/OS-Mac\"\n\t , \"clean-platform\/OS-Posix\"\n\t , \"clean-platform\/OS-Windows\"\n\t , \"clean-platform\/OS-Windows-32\"\n\t , \"clean-platform\/OS-Windows-64\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > builddb.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (mods, w) = findModules` cli.libs cli.root w\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop mods 'DB'.newDb cache w\n\t# f = 'DB'.saveDb db f\n\t= fclose f w\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: [(String,String)] 'DB'.TypeDB *DclCache *World -> *('DB'.TypeDB, *World)\n\tloop [] db _ w = (db,w)\n\tloop [(lib,mod):list] db cache w\n\t# (db, cache, w) = getModuleTypes mod lib cache db w\n\t\/\/# db = 'DB'.putTypes sts db\n\t= loop list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[x:c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\/\/ Libraries Library Module\nfindModules` :: ![String] !String !*World -> *(![(String,String)], !*World)\nfindModules` [] _ w = ([], w)\nfindModules` [lib:libs] root w\n#! (mods, w) = findModules lib root w\n#! (moremods, w) = findModules` libs root w\n= (removeDup (mods ++ moremods), w)\n\nfindModules :: !String !String !*World -> *(![(String,String)], !*World)\nfindModules lib root w\n#! (fps, w) = readDirectory (root +++ \"\/\" +++ lib) w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (tuple (root +++ lib)) $ map (\\s->s%(0,size s-5)) $ filter isDclModule fps\n#! (moremods, w) = findModules` (map ((+++) (lib+++\"\/\")) (filter isDirectory fps)) root w\n= (removeDup (mods ++ moremods), w)\nwhere\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\" && s.[0] <> '_'\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String String *DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes mod lib cache db w\n# filename = lib +++ \"\/\" +++ mkdir mod +++ \".dcl\"\n# (ok,f,w) = fopen filename FReadText w\n| not ok = abort (\"Couldn't open file \" +++ filename +++ \".\\n\")\n# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n cache = {cache & hash_table=ht}\n# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" False mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n cache = {cache & hash_table=ht}\n# (ok,w) = fclose f w\n| not ok = abort (\"Couldn't close file \" +++ filename +++ \".\\n\")\n# mod = pm.mod_ident.id_name\n# db = 'DB'.putTypes (pd_typespecs mod pm.mod_defs) db\n# db = 'DB'.putInstancess (pd_instances mod pm.mod_defs) db\n# db = 'DB'.putClasses (pd_classes mod pm.mod_defs) db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = {if (c == '.') '\/' c\\\\c<-:s}\n\n\tpd_typespecs :: String [ParsedDefinition] -> [('DB'.FunctionLocation, 'DB'.Type)]\n\tpd_typespecs mod pds\n\t# pds = filter (\\pd->case pd of (PD_TypeSpec _ _ _ _ _)=True; _=False) pds\n\t# sts = map (\\(PD_TypeSpec pos id prio st funspecs) -> ('DB'.FL lib mod id.id_name,st)) pds\n\t# sts = filter (\\st->case st of (_,(Yes _))=True; _=False) sts\n\t# sts = map (\\(loc,Yes x)->(loc,'T'.toType x)) sts\n\t= sts\n\n\tpd_instances :: String [ParsedDefinition] -> [('DB'.Class, ['DB'.Type])]\n\tpd_instances mod pds\n\t# pds = filter (\\pd->case pd of (PD_Instance _)=True; _=False) pds\n\t= map (\\(PD_Instance {pim_pi={pi_ident,pi_types}})\n\t\t-> (pi_ident.id_name, map 'T'.toType pi_types)) pds\n\n\tpd_classes :: String [ParsedDefinition]\n\t\t-> [('DB'.ClassLocation, ['T'.TypeVar], [('DB'.FunctionName, 'T'.Type)])]\n\tpd_classes mod pds\n\t# pds = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) pds\n\t= map (\\(PD_Class {class_ident={id_name},class_args} pds)\n\t\t-> let typespecs = pd_typespecs mod pds\n\t\tin ('DB'.CL lib mod id_name, map 'T'.toTypeVar class_args, \n\t\t\t[(f,t) \\\\ ('DB'.FL _ _ f, t) <- typespecs])) pds\n\nunigroups :: (Type Type -> Bool) [(a,Type)] -> [([a],Type)]\nunigroups f ts = unigroups` ts []\nwhere\n\tunigroups` [] groups = groups\n\tunigroups` [(a,t):ts] [] = unigroups` ts [([a],t)]\n\tunigroups` [(a,t):ts] [(ns,ut):groups]\n\t| f t ut\t= unigroups` ts [([a:ns],ut):groups]\n\t| otherwise = unigroups` ts [(ns,ut):unigroups` [(a,t)] groups]\n\n(<+) infixr 5 :: a b -> [String] | print a & print b\n(<+) a b = print a ++ print b\n\njoin :: a [b] -> [String] | print a & print b\njoin _ [] = []\njoin a [b:[]] = print b\njoin a [b:bs] = b <+ a <+ join a bs\n\nalignl :: Int a -> [String] | print a\nalignl i s\n# s = print s\n# len = sum (map size s)\n| len >= i = s\n| otherwise = s ++ [{' ' \\\\ i <- [0..i-len]}]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","old_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\n\n\/\/ StdEnv\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nfrom Text import class Text(concat), instance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String\nimport CoclUtils\n\n\/\/ frontend\n\/\/import Heap, compile, parse, predef\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents), ::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr, ::Position(NoPos), ::Module{mod_ident,mod_defs}, ::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class), ::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType, ::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_types}, ::Type, ::ClassDef{class_ident,class_args}, ::TypeVar\nfrom parse import wantModule\n\n:: CLI = {\n\thelp :: Bool,\n\tversion :: Bool,\n\troot :: String,\n\tlibs :: [String]}\n\ninstance zero CLI where\n\tzero = {\n\t\tversion = False,\n\t\thelp = False,\n\t\troot = \"\/opt\/clean\/lib\/\",\n\t\tlibs = [\n\t\t\t \"StdEnv\"\n\t\t\t, \"StdLib\"\n\t\t\t, \"ArgEnv\"\n\t\t\t, \"Directory\"\n\t\t\t, \"Dynamics\"\n\t\t\t, \"Gast\"\n\t\t\t, \"Generics\"\n\t\t\t, \"MersenneTwister\"\n\t\t\t, \"TCPIP\"\n\t\t\t, \"clean-platform\/OS-Independent\"\n\t\t\t, \"clean-platform\/OS-Linux\"\n\t\t\t, \"clean-platform\/OS-Linux-32\"\n\t\t\t, \"clean-platform\/OS-Linux-64\"\n\t\t\t, \"clean-platform\/OS-Mac\"\n\t\t\t, \"clean-platform\/OS-Posix\"\n\t\t\t, \"clean-platform\/OS-Windows\"\n\t\t\t, \"clean-platform\/OS-Windows-32\"\n\t\t\t, \"clean-platform\/OS-Windows-64\"]}\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > builddb.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (mods, w) = findModules` cli.libs cli.root w\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop mods 'DB'.newDb cache w\n\t# f = 'DB'.saveDb db f\n\t= fclose f w\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: [(String,String)] 'DB'.TypeDB *DclCache *World -> *('DB'.TypeDB, *World)\n\tloop [] db _ w = (db,w)\n\tloop [(lib,mod):list] db cache w\n\t# (db, cache, w) = getModuleTypes mod lib cache db w\n\t\/\/# db = 'DB'.putTypes sts db\n\t= loop list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[x:c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\/\/ Libraries Library Module\nfindModules` :: ![String] !String !*World -> *(![(String,String)], !*World)\nfindModules` [] _ w = ([], w)\nfindModules` [lib:libs] root w\n#! (mods, w) = findModules lib root w\n#! (moremods, w) = findModules` libs root w\n= (removeDup (mods ++ moremods), w)\n\nfindModules :: !String !String !*World -> *(![(String,String)], !*World)\nfindModules lib root w\n#! (fps, w) = readDirectory (root +++ \"\/\" +++ lib) w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (tuple (root +++ lib)) $ map (\\s->s%(0,size s-5)) $ filter isDclModule fps\n#! (moremods, w) = findModules` (map ((+++) (lib+++\"\/\")) (filter isDirectory fps)) root w\n= (removeDup (mods ++ moremods), w)\nwhere\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\" && s.[0] <> '_'\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String String *DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes mod lib cache db w\n# filename = lib +++ \"\/\" +++ mkdir mod +++ \".dcl\"\n# (ok,f,w) = fopen filename FReadText w\n| not ok = abort (\"Couldn't open file \" +++ filename +++ \".\\n\")\n# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n cache = {cache & hash_table=ht}\n# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" False mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n cache = {cache & hash_table=ht}\n# (ok,w) = fclose f w\n| not ok = abort (\"Couldn't close file \" +++ filename +++ \".\\n\")\n# mod = pm.mod_ident.id_name\n# db = 'DB'.putTypes (pd_typespecs mod pm.mod_defs) db\n# db = 'DB'.putInstancess (pd_instances mod pm.mod_defs) db\n# db = 'DB'.putClasses (pd_classes mod pm.mod_defs) db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = {if (c == '.') '\/' c\\\\c<-:s}\n\n\tpd_typespecs :: String [ParsedDefinition] -> [('DB'.FunctionLocation, 'DB'.Type)]\n\tpd_typespecs mod pds\n\t# pds = filter (\\pd->case pd of (PD_TypeSpec _ _ _ _ _)=True; _=False) pds\n\t# sts = map (\\(PD_TypeSpec pos id prio st funspecs) -> ('DB'.FL lib mod id.id_name,st)) pds\n\t# sts = filter (\\st->case st of (_,(Yes _))=True; _=False) sts\n\t# sts = map (\\(loc,Yes x)->(loc,'T'.toType x)) sts\n\t= sts\n\n\tpd_instances :: String [ParsedDefinition] -> [('DB'.Class, ['DB'.Type])]\n\tpd_instances mod pds\n\t# pds = filter (\\pd->case pd of (PD_Instance _)=True; _=False) pds\n\t= map (\\(PD_Instance {pim_pi={pi_ident,pi_types}})\n\t\t-> (pi_ident.id_name, map 'T'.toType pi_types)) pds\n\n\tpd_classes :: String [ParsedDefinition]\n\t\t-> [('DB'.ClassLocation, ['T'.TypeVar], [('DB'.FunctionName, 'T'.Type)])]\n\tpd_classes mod pds\n\t# pds = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) pds\n\t= map (\\(PD_Class {class_ident={id_name},class_args} pds)\n\t\t-> let typespecs = pd_typespecs mod pds\n\t\tin ('DB'.CL lib mod id_name, map 'T'.toTypeVar class_args, \n\t\t\t[(f,t) \\\\ ('DB'.FL _ _ f, t) <- typespecs])) pds\n\nunigroups :: (Type Type -> Bool) [(a,Type)] -> [([a],Type)]\nunigroups f ts = unigroups` ts []\nwhere\n\tunigroups` [] groups = groups\n\tunigroups` [(a,t):ts] [] = unigroups` ts [([a],t)]\n\tunigroups` [(a,t):ts] [(ns,ut):groups]\n\t| f t ut\t= unigroups` ts [([a:ns],ut):groups]\n\t| otherwise = unigroups` ts [(ns,ut):unigroups` [(a,t)] groups]\n\n(<+) infixr 5 :: a b -> [String] | print a & print b\n(<+) a b = print a ++ print b\n\njoin :: a [b] -> [String] | print a & print b\njoin _ [] = []\njoin a [b:[]] = print b\njoin a [b:bs] = b <+ a <+ join a bs\n\nalignl :: Int a -> [String] | print a\nalignl i s\n# s = print s\n# len = sum (map size s)\n| len >= i = s\n| otherwise = s ++ [{' ' \\\\ i <- [0..i-len]}]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"6a8d043a184171c0051172fa603202ba066f0f51","subject":"Put back copyArray example for uniqueness syntax documentation (shows parentheses)","message":"Put back copyArray example for uniqueness syntax documentation (shows parentheses)\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \"[\", \"]\", \".\", \":\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:... | [...<=...]\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [...<=...]`).\"\n\t\t, \"\\n\\nNote that when using unique types in a function or an ADT the container must also be unique.\"\n\t\t, \"For instance, `T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"\\n\\nFunctions have to be split up into arity 1 and the sub functions need to be annotated as well.\"\n\t\t, \"For instance, `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parenthesis when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \"[\", \"]\", \".\", \":\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:... | [...<=...]\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [...<=...]`).\"\n\t\t, \"\\n\\nNote that when using unique types in a function or an ADT the container must also be unique.\"\n\t\t, \"For instance, `T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"\\n\\nFunctions have to be split up into arity 1 and the sub functions need to be annotated as well.\"\n\t\t, \"For instance, `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"f07f10bbdac3daa19c6baee3430a1eebda66b9db","subject":"added programming language Clean to the GitHub repo","message":"added programming language Clean to the GitHub repo\n","repos":"florianbussmann\/hello-world,florianbussmann\/hello-world,florianbussmann\/hello-world,florianbussmann\/hello-world,florianbussmann\/hello-world,florianbussmann\/hello-world,florianbussmann\/hello-world,florianbussmann\/hello-world,florianbussmann\/hello-world,florianbussmann\/hello-world,florianbussmann\/hello-world,florianbussmann\/hello-world","old_file":"hello-clean\/hello-clean.icl","new_file":"hello-clean\/hello-clean.icl","new_contents":"module hello\nStart :: {#Char}\nStart = \"Hello, World.\"","old_contents":"","returncode":1,"stderr":"error: pathspec 'hello-clean\/hello-clean.icl' did not match any file(s) known to git\n","license":"mit","lang":"Clean"} {"commit":"3352b1c361c6969e966d072132447c798a02d534","subject":"Oops, change dir after parsing config file","message":"Oops, change dir after parsing config file\n","repos":"ErinvanderVeen\/Clone,ErinvanderVeen\/Clone","old_file":"src\/Clone.icl","new_file":"src\/Clone.icl","new_contents":"module Clone\n\nimport Config, BotQueue, Bot\nimport Data.Maybe, Data.List\nfrom System._Posix import select_, chdir\nfrom System._Pointer import :: Pointer\nfrom StdListExtensions import foldrSt\nimport StdString, StdInt\n\nStart world\n# queue = newBotQueue\n# (config, world) = parseConfig world\n\/\/ Platform hasn't yet implemented workingdir for runProcessIO\n\/\/ So we must physically change dir\n# (_, world) = chdir \"bots\/\" world\n# queue = foldr addIfRootBot queue config.bots\n= loop config queue world\n\nloop :: Config BotQueue !*World -> ()\nloop config queue world\n# queue = decrementAll queue\n# (queue, world) = runRequiredBots config queue world\n# (_, world) = waitMinute world\n= loop config queue world\n\nrunRequiredBots :: Config BotQueue !*World -> (!BotQueue, !*World)\nrunRequiredBots config queue world\n# (requiredBots, queue) = allBotsOnZero queue\n# (queue, world) = foldrSt (\\b (q, w) -> runBotAndChildren q config b w) requiredBots (queue, world)\n| runRequired queue = runRequiredBots config queue world\n| otherwise = (queue, world)\n\nrunBotAndChildren :: !BotQueue Config Bot !*World -> (!BotQueue, !*World)\nrunBotAndChildren queue config bot world\n# (result, world) = runBot bot world\n# queue = addIfRootBot (findBot config bot.name) queue\n| isNothing result = (queue, world)\n# children = [findBot config x \\\\ x <- bot.children]\n# children = map (\\c -> {c & input = result}) children\n# queue = foldr addToQueue queue children\n= (queue, world)\nwhere\n\tfindBot :: Config String -> Bot\n\tfindBot config name = fromJust (find (\\b -> b.name == name) config.bots)\n\naddToQueue :: Bot BotQueue -> BotQueue\naddToQueue bot queue = insertBot queue bot\n\naddIfRootBot :: Bot BotQueue -> BotQueue\naddIfRootBot bot queue\n| bot.root = addToQueue bot queue\n| otherwise = queue\n\nwaitMinute :: !*World -> (!Int, !*World)\nwaitMinute w = code {\n\tccall waitMinute \":I:A\"\n}\n","old_contents":"module Clone\n\nimport Config, BotQueue, Bot\nimport Data.Maybe, Data.List\nfrom System._Posix import select_, chdir\nfrom System._Pointer import :: Pointer\nfrom StdListExtensions import foldrSt\nimport StdString, StdInt\n\nStart world\n\/\/ Platform hasn't yet implemented workingdir for runProcessIO\n\/\/ So we must physically change dir\n# (_, world) = chdir \"bots\/\" world\n# queue = newBotQueue\n# (config, world) = parseConfig world\n# queue = foldr addIfRootBot queue config.bots\n= loop config queue world\n\nloop :: Config BotQueue !*World -> ()\nloop config queue world\n# queue = decrementAll queue\n# (queue, world) = runRequiredBots config queue world\n# (_, world) = waitMinute world\n= loop config queue world\n\nrunRequiredBots :: Config BotQueue !*World -> (!BotQueue, !*World)\nrunRequiredBots config queue world\n# (requiredBots, queue) = allBotsOnZero queue\n# (queue, world) = foldrSt (\\b (q, w) -> runBotAndChildren q config b w) requiredBots (queue, world)\n| runRequired queue = runRequiredBots config queue world\n| otherwise = (queue, world)\n\nrunBotAndChildren :: !BotQueue Config Bot !*World -> (!BotQueue, !*World)\nrunBotAndChildren queue config bot world\n# (result, world) = runBot bot world\n# queue = addIfRootBot (findBot config bot.name) queue\n| isNothing result = (queue, world)\n# children = [findBot config x \\\\ x <- bot.children]\n# children = map (\\c -> {c & input = result}) children\n# queue = foldr addToQueue queue children\n= (queue, world)\nwhere\n\tfindBot :: Config String -> Bot\n\tfindBot config name = fromJust (find (\\b -> b.name == name) config.bots)\n\naddToQueue :: Bot BotQueue -> BotQueue\naddToQueue bot queue = insertBot queue bot\n\naddIfRootBot :: Bot BotQueue -> BotQueue\naddIfRootBot bot queue\n| bot.root = addToQueue bot queue\n| otherwise = queue\n\nwaitMinute :: !*World -> (!Int, !*World)\nwaitMinute w = code {\n\tccall waitMinute \":I:A\"\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"e03dccfc91bcbeb3669cce4428b787d3cb445f7c","subject":"add foreign to syntax builtins","message":"add foreign to syntax builtins\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/BuiltinSyntax.icl","new_file":"backend\/BuiltinSyntax.icl","new_contents":"implementation module BuiltinSyntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle\n\nimport CloogleDB\n\nimport Builtins\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module BuiltinSyntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle\n\nimport CloogleDB\n\nimport Builtins\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\\n\\n\" +\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"6f44fac1024cbcdc2567c58a2b6fc316b9bb92a9","subject":"Add note about binumap","message":"Add note about binumap\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_basicvalues\n\t, bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_basicvalues =\n\t{ syntax_title = \"basic values\"\n\t, syntax_patterns = map exact [\"'.'\", \"[+-]?\\\\d+\", \"[+-]?0[0-7]+\", \"[-+]?0x[0-9a-fA-F]+\", \"E\"]\n\t, syntax_code = [\"0x...\", \"0...\", \"'...'\", \"...E...\"]\n\t, syntax_description =\n\t\t\"Constant basic values can be of type {{`Int`}}, {{`Char`}} and {{`Real`}}. See also {{`Bool`}}.\\n\\n\" +\n\t\t\"Integers can be specified in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix) notation.\\n\\n\" +\n\t\t\"Characters can either be printable characters (except `'`) or an escape sequence.\\n\" +\n\t\t\"An escape sequence is a character escape, a hexademical escape (starting with `x`), an octal escape (starting with `0` to `7`) or a decimal escape (starting with `d`).\\n\\n\" +\n\t\t\"Reals can be suffixed by a power of ten in the scientific notation.\\n\\n\" +\n\t\t\"Basic values can also be pattern matched with these notations.\"\n\t, syntax_doc_locations = [CLR 6 \"4.1.1\" \"_Toc311798017\"]\n\t, syntax_examples = map (EXs \"rhs\")\n\t\t[ \"(42, -42, +42) \/\/ Tuple with 42, -42 and 42 in decimal notation\"\n\t\t, \"(052, -052, +052) \/\/ Tuple with 42, -42 and 42 in octal notation\"\n\t\t, \"(0x2a, -0x2a, +0x2A) \/\/ Tuple with 42, -42 and 42 in hexadecimal notation\"\n\t\t, \"('a', '\\\\x2a', '\\\\052') \/\/ Tuple with a normal character and twice the character with ASCII value 42\"\n\t\t, \"['\\\\n', '\\\\r', '\\\\f', '\\\\b', '\\\\t', '\\\\v', '\\\\', '\\\\'', '\\\\\\\"']\\n\" +\n\t\t \" \/\/ All character escapes\"\n\t\t, \"(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\\n\" +\n\t\t \" \/\/ Several reals\"\n\t\t]\n\t}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\", \"\\\\*\/\", \"comments?\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\", \"*!\"]\n\t, syntax_code = [\"generic ... ... [| ...] [*!] :: ... \", \"derive ... ... [of ...] [with ...]\"]\n\t, syntax_description = \"With generics, a kind indexed function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples = map EX\n\t\t[ \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, \"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context. The context will become an argument.\\n\" +\n\t\t \"derive gFun CONS of {gcd_arity} with f _ \/\/ A derivation that does not use all arguments. The compiler can optimize even more.\\n\" +\n\t\t \"gFun{|CONS of {gcd_arity}|} f _ = \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t, \"generic gShared a *! :: ... \/\/ Derive a generic function using a shared bimap (very experimental, see https:\/\/gitlab.science.ru.nl\/clean-and-itasks\/clean-language-report\/blob\/master\/experimental\/binumap.md).\\n\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t, \"abc ['abc':rest] = True \/\/ The special syntax can als be used to patternmatch\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_basicvalues\n\t, bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_basicvalues =\n\t{ syntax_title = \"basic values\"\n\t, syntax_patterns = map exact [\"'.'\", \"[+-]?\\\\d+\", \"[+-]?0[0-7]+\", \"[-+]?0x[0-9a-fA-F]+\", \"E\"]\n\t, syntax_code = [\"0x...\", \"0...\", \"'...'\", \"...E...\"]\n\t, syntax_description =\n\t\t\"Constant basic values can be of type {{`Int`}}, {{`Char`}} and {{`Real`}}. See also {{`Bool`}}.\\n\\n\" +\n\t\t\"Integers can be specified in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix) notation.\\n\\n\" +\n\t\t\"Characters can either be printable characters (except `'`) or an escape sequence.\\n\" +\n\t\t\"An escape sequence is a character escape, a hexademical escape (starting with `x`), an octal escape (starting with `0` to `7`) or a decimal escape (starting with `d`).\\n\\n\" +\n\t\t\"Reals can be suffixed by a power of ten in the scientific notation.\\n\\n\" +\n\t\t\"Basic values can also be pattern matched with these notations.\"\n\t, syntax_doc_locations = [CLR 6 \"4.1.1\" \"_Toc311798017\"]\n\t, syntax_examples = map (EXs \"rhs\")\n\t\t[ \"(42, -42, +42) \/\/ Tuple with 42, -42 and 42 in decimal notation\"\n\t\t, \"(052, -052, +052) \/\/ Tuple with 42, -42 and 42 in octal notation\"\n\t\t, \"(0x2a, -0x2a, +0x2A) \/\/ Tuple with 42, -42 and 42 in hexadecimal notation\"\n\t\t, \"('a', '\\\\x2a', '\\\\052') \/\/ Tuple with a normal character and twice the character with ASCII value 42\"\n\t\t, \"['\\\\n', '\\\\r', '\\\\f', '\\\\b', '\\\\t', '\\\\v', '\\\\', '\\\\'', '\\\\\\\"']\\n\" +\n\t\t \" \/\/ All character escapes\"\n\t\t, \"(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\\n\" +\n\t\t \" \/\/ Several reals\"\n\t\t]\n\t}\n\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\", \"\\\\*\/\", \"comments?\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... [| ...] :: ... \", \"derive ... ... [of ...] [with ...]\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples = map EX\n\t\t[ \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, \"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context. The context will become an argument.\\n\" +\n\t\t \"derive gFun CONS of {gcd_arity} with f _ \/\/ A derivation that does not use all arguments. The ompiler can optimize even more\\n\" +\n\t\t \"gFun{|CONS of {gcd_arity}|} f _ = \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t, \"abc ['abc':rest] = True \/\/ The special syntax can als be used to patternmatch\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"53c202de23c5295476bbea429d249ae4fcdbb04b","subject":"Fix issue with SoccerFun StdLibExt returned on StdLib search","message":"Fix issue with SoccerFun StdLibExt returned on StdLib search\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , libraries :: Maybe ([String], Bool)\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , dcl_line :: Maybe Int\n , distance :: Int\n , builtin :: Maybe Bool\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , recordfield_of :: Maybe String\n , generic_derivations :: Maybe [String]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [(String, [(String,String,Maybe Int)])]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , libraries = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_INVALIDNAME \"function name too long\", w)\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= (err E_INVALIDNAME \"name cannot contain spaces\", w)\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= (err E_INVALIDTYPE \"couldn't parse type\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= map (uncurry (makeTypeResult (Just typeName))) types\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case name of\n\t\t\tNothing = []\n\t\t\t(Just n) = findMacro` (\\loc _ -> isNameMatch (size n-2) n loc) db\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _) _ _ f _ -> isNameMatch\n\t\t (size n-2) n (Location lib mod Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case lcName of\n\t\t\t(Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\tNothing = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\(Location _ _ _ c`) _ _ _ -> toLowerCase c` == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult (Location lib mod line cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" \" + concat (print False cc)\n\t\t , class_funs = [concat $ print False fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [(concat (print False t), map loc ls) \\\\ (t,ls) <- getInstances cls db]\n\t\t }\n\t\t )\n\twhere\n\t\tloc :: Location -> (String, String, Maybe Int)\n\t\tloc (Location lib mod ln _) = (lib, mod, ln)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef -> Result\n\tmakeTypeResult mbName (Location lib mod line t) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = concat $ print False (fname,et)\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if (tes.te_isconstructor)\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if (tes.te_isrecordfield)\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t (\\_ -> [concat $ print False d \\\\ d <-derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,builtin) = case fl of\n\t\t\t(Location l m ln f) = (l, m, f, ln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= toInt $ sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)]\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= levenshtein` orgsearch fname\n\t\twhere\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein a b\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg +\n\t\t\tif (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\" + \")\\n\"\n\tmsgToString _ _ = \"\"\n","old_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , libraries :: Maybe ([String], Bool)\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , dcl_line :: Maybe Int\n , distance :: Int\n , builtin :: Maybe Bool\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , recordfield_of :: Maybe String\n , generic_derivations :: Maybe [String]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [(String, [(String,String,Maybe Int)])]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , libraries = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_INVALIDNAME \"function name too long\", w)\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= (err E_INVALIDNAME \"name cannot contain spaces\", w)\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= (err E_INVALIDTYPE \"couldn't parse type\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= map (uncurry (makeTypeResult (Just typeName))) types\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case name of\n\t\t\tNothing = []\n\t\t\t(Just n) = findMacro` (\\loc _ -> isNameMatch (size n-2) n loc) db\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _) _ _ f _ -> isNameMatch\n\t\t (size n-2) n (Location lib mod Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case lcName of\n\t\t\t(Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\tNothing = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\(Location _ _ _ c`) _ _ _ -> toLowerCase c` == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult (Location lib mod line cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" \" + concat (print False cc)\n\t\t , class_funs = [concat $ print False fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [(concat (print False t), map loc ls) \\\\ (t,ls) <- getInstances cls db]\n\t\t }\n\t\t )\n\twhere\n\t\tloc :: Location -> (String, String, Maybe Int)\n\t\tloc (Location lib mod ln _) = (lib, mod, ln)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef -> Result\n\tmakeTypeResult mbName (Location lib mod line t) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = concat $ print False (fname,et)\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if (tes.te_isconstructor)\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if (tes.te_isrecordfield)\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t (\\_ -> [concat $ print False d \\\\ d <-derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,builtin) = case fl of\n\t\t\t(Location l m ln f) = (l, m, f, ln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= toInt $ sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)]\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= levenshtein` orgsearch fname\n\t\twhere\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein a b\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _) = any (\\l -> indexOf l lib <> -1) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg +\n\t\t\tif (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\" + \")\\n\"\n\tmsgToString _ _ = \"\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"840f4fd6696c7af6f42251cbb263fe7c86ff2e7b","subject":"fix ircbot code","message":"fix ircbot code\n","repos":"clean-cloogle\/clean-irc","old_file":"IRCBot.icl","new_file":"IRCBot.icl","new_contents":"implementation module IRCBot\n\nfrom Data.Func import $\nimport Data.Either\nimport Data.Error\nimport Data.Maybe\nimport IRC\nimport TCPIP\n\nfrom Text import class Text(split,join), instance Text String\n\nimport StdList\nimport StdBool\n\nTIMEOUT :== Just 1000\n\nbot :: (String, Int) [IRCMessage] [IRCMessage] .a (IRCMessage .a *World -> *(Maybe [IRCMessage], .a, *World)) *World -> *(Maybe String, .a, *World)\nbot (host, port) start end state bot w\n\/\/Lookup hostname\n# (ip, w) = lookupIPAddress host w\n| isNothing ip\n\t= (Just $ \"DNS lookup for \" +++ host +++ \" failed\", state, w)\n\/\/Connect\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (fromJust ip, port) w\n| rpt == TR_Expired\n\t= (Just $ \"Connection to \" +++ host +++ \" timed out\", state, w)\n| rpt == TR_NoSuccess\n\t= (Just $ \"Could not connect to \" +++ host, state, w)\n\/\/ Send startup commands\n# (merr, chan, w) = send (map toString start) (fromJust chan) w\n| isError merr = (Just $ fromError merr, state, w)\n\/\/Start processing function\n# (mer, chan, state, w) = process chan \"\" state bot w\n| isError mer = (Just $ fromError mer, state, w)\n\/\/ Send shutdown commands\n# (merr, {rChannel,sChannel}, w) = send (map toString end) chan w\n| isError merr = (Just $ fromError merr, state, w)\n\/\/Close channels\n= (Nothing, state, closeChannel sChannel (closeRChannel rChannel w))\n\nprocess :: TCP_DuplexChannel String .a (IRCMessage .a *World -> *(Maybe [IRCMessage], .a, *World)) *World -> *(MaybeErrorString (), TCP_DuplexChannel, .a, *World)\nprocess chan acc state bot w\n\/\/See if we have a message\n= case split \"\\r\\n\" acc of\n\t\/\/We only have one message that is not complete\n\t[m] \n\t\t\/\/Receive\n\t\t# (merr_resp, chan, w) = recv chan w\n\t\t| isError merr_resp = (Error (fromError merr_resp), chan, state, w)\n\t\t# (Ok mresp) = merr_resp\n\t\t| isNothing mresp = process chan acc state bot w\n\t\t= process chan (m +++ fromJust mresp) state bot w\n\t\/\/We have a successfull split and therefore we process at least one message\n\t[m:xs]\n\t\t# acc = join \"\\r\\n\" xs\n\t\t= case parseIRCMessage $ m +++ \"\\r\\n\" of\n\t\t\t(Left err) = (Error $ \"IRC Parsing error: \" +++ join \"\\n\" err, chan, state, w)\n\t\t\t(Right msg)\n\t\t\t# (mircc, state, w) = bot msg state w\n\t\t\t| isNothing mircc = (Ok (), chan, state, w) \/\/ Bot asks to quit\n\t\t\t\/\/Possible send the commands\n\t\t\t# (merr, chan, w) = send (map toString $ fromJust mircc) chan w\n\t\t\t| isError merr = (Error $ fromError merr, chan, state, w)\n\t\t\t\/\/Recurse\n\t\t\t= process chan acc state bot w\n\nsend :: ![String] !TCP_DuplexChannel !*World -> (!MaybeErrorString (), !TCP_DuplexChannel, !*World)\nsend [] chan w = (Ok (), chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = (Error \"Could not send message\", {sChannel=sChannel,rChannel=rChannel}, w)\n# (_, w) = sleep 500000 w\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\twhere\n\t\tsleep :: !Int !*World -> (!Int, *World)\n\t\tsleep i w = code {\n\t\t\t\tccall usleep \"I:I:A\"\n\t\t\t}\n\nrecv :: TCP_DuplexChannel *World -> (MaybeErrorString (Maybe String), TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Ok Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = (Error \"Timeout recv fail\", {sChannel=sChannel,rChannel=rChannel}, w)\n= (Ok $ Just $ toString $ fromJust resp, {sChannel=sChannel,rChannel=rChannel}, w)\n","old_contents":"implementation module IRCBot\n\nfrom Data.Func import $\nimport Data.Either\nimport Data.Error\nimport Data.Maybe\nimport IRC\nimport TCPIP\n\nfrom Text import class Text(split,join), instance Text String\n\nimport StdList\nimport StdBool\n\nTIMEOUT :== Just 1000\n\nbot :: (String, Int) [IRCMessage] [IRCMessage] .a (IRCMessage .a *World -> .(Maybe [IRCMessage], .a, *World)) *World -> *(Maybe String, .a, *World)\nbot (host, port) start end state bot w\n\/\/Lookup hostname\n# (ip, w) = lookupIPAddress host w\n| isNothing ip\n\t= (Error $ \"DNS lookup for \" +++ host +++ \" failed\", state, w)\n\/\/Connect\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (fromJust ip, port) w\n| rpt == TR_Expired\n\t= (Error $ \"Connection to \" +++ host +++ \" timed out\", state, w)\n| rpt == TR_NoSuccess\n\t= (Error $ \"Could not connect to \" +++ host, state, w)\n\/\/ Send startup commands\n# (merr, chan, w) = send (map toString start) (fromJust chan) w\n| isError merr = (Error $ fromError merr, state, w)\n\/\/Start processing function\n# (mer, chan, state, w) = process chan \"\" state bot w\n| isError mer = (Error $ fromError mer, state, w)\n\/\/ Send shutdown commands\n# (merr, {rChannel,sChannel}, w) = send (map toString end) chan w\n| isError merr = (Error $ fromError merr, state, w)\n\/\/Close channels\n= (Ok state, state, closeChannel sChannel (closeRChannel rChannel w))\n\nprocess :: TCP_DuplexChannel String .a (IRCMessage .a *World -> *(Maybe [IRCMessage], .a, *World)) *World -> *(MaybeErrorString (), TCP_DuplexChannel, .a, *World)\nprocess chan acc state bot w\n\/\/See if we have a message\n= case split \"\\r\\n\" acc of\n\t\/\/We only have one message that is not complete\n\t[m] \n\t\t\/\/Receive\n\t\t# (merr_resp, chan, w) = recv chan w\n\t\t| isError merr_resp = (Error (fromError merr_resp), chan, state, w)\n\t\t# (Ok mresp) = merr_resp\n\t\t| isNothing mresp = process chan acc state bot w\n\t\t= process chan (m +++ fromJust mresp) state bot w\n\t\/\/We have a successfull split and therefore we process at least one message\n\t[m:xs]\n\t\t# acc = join \"\\r\\n\" xs\n\t\t= case parseIRCMessage $ m +++ \"\\r\\n\" of\n\t\t\t(Left err) = (Error $ \"IRC Parsing error: \" +++ join \"\\n\" err, chan, state, w)\n\t\t\t(Right msg)\n\t\t\t# (mircc, state, w) = bot msg state w\n\t\t\t| isNothing mircc = (Ok (), chan, state, w) \/\/ Bot asks to quit\n\t\t\t\/\/Possible send the commands\n\t\t\t# (merr, chan, w) = send (map toString $ fromJust mircc) chan w\n\t\t\t| isError merr = (Error $ fromError merr, chan, state, w)\n\t\t\t\/\/Recurse\n\t\t\t= process chan acc state bot w\n\nsend :: ![String] !TCP_DuplexChannel !*World -> (!MaybeErrorString (), !TCP_DuplexChannel, !*World)\nsend [] chan w = (Ok (), chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = (Error \"Could not send message\", {sChannel=sChannel,rChannel=rChannel}, w)\n# (_, w) = sleep 500000 w\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\twhere\n\t\tsleep :: !Int !*World -> (!Int, *World)\n\t\tsleep i w = code {\n\t\t\t\tccall usleep \"I:I:A\"\n\t\t\t}\n\nrecv :: TCP_DuplexChannel *World -> (MaybeErrorString (Maybe String), TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Ok Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = (Error \"Timeout recv fail\", {sChannel=sChannel,rChannel=rChannel}, w)\n= (Ok $ Just $ toString $ fromJust resp, {sChannel=sChannel,rChannel=rChannel}, w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"5e8ed994a300b926e35610d4fb95c7c3b12d69c1","subject":"Add foreign to the builtins","message":"Add foreign to the builtins\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org","old_file":"backend\/BuiltinSyntax.icl","new_file":"backend\/BuiltinSyntax.icl","new_contents":"implementation module BuiltinSyntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle\n\nimport CloogleDB\n\nimport Builtins\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\\n\\n\" +\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module BuiltinSyntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle\n\nimport CloogleDB\n\nimport Builtins\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"ba97c0f2d0c9476ae3fb3c3eb82b4fd157104073","subject":"Some more syntax constructs","message":"Some more syntax constructs\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle","old_file":"backend\/BuiltinSyntax.icl","new_file":"backend\/BuiltinSyntax.icl","new_contents":"implementation module BuiltinSyntax\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nimport Data.Maybe\nimport Text\n\nimport Cloogle\nimport CloogleDB\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t bs_arrays ++\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_let\n\t, bs_let_before\n\t] ++ bs_lists ++\n\t[ bs_macro\n\t, bs_module\n\t, bs_otherwise\n\t\/\/ TODO bs_selection (arrays and records)\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t] ++ bs_tuples ++\n\t[ bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t\/\/ TODO bs_zf\n\t]\n\nCLR :: Int String String -> SyntaxDocLocation\nCLR f sec h = CleanLangReport\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_arrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\nwhere\n\tmake_array :: [Char] -> ([SyntaxPattern], SyntaxEntry)\n\tmake_array k = ([\"array\", typec, toString (['{':k]++['\\\\w}'])],\n\t\t{ syntax_title = kind + \"array\"\n\t\t, syntax_code = [typec]\n\t\t, syntax_description = \"An array contains a finite number of elements of the same type. Access time is constant.\"\n\t\t, syntax_doc_location = [CLR 6 \"4.4\" \"_Toc311798029\"]\n\t\t, syntax_examples = [EX \"Function\" (\"xs :: {\" <+ k <+ \"Int}\\nxs = {\" <+ k <+ \"1,3,6,10}\")]\n\t\t})\n\twhere\n\t\ttypec = toString (['{':k]++['}'])\n\t\tkind = case k of\n\t\t\t[] -> \"\"\n\t\t\t['!'] -> \"strict \"\n\t\t\t['#'] -> \"unboxed \"\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_location = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_class = ([\"class\"],\n\t{ syntax_title = \"class\"\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_location = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t})\n\nbs_code = ([\"code\", \"inline\", \"code inline\"],\n\t{ syntax_title = \"ABC code\"\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_location = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_location = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_location = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_location = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_location = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_location = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_location = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_location = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_instance = ([\"instance\"],\n\t{ syntax_title = \"instance\"\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_location = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_location = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_location = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_lists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\nwhere\n\tmake_list :: [Char] [Char] -> ([SyntaxPattern], SyntaxEntry)\n\tmake_list k s = ([higherorder, listany, \"list\"],\n\t\t{ syntax_title = \"lists\"\n\t\t, syntax_code = [higherorder]\n\t\t, syntax_description = \"A\" + kind + spine + \" list.\\n\\n\" + description\n\t\t, syntax_doc_location = [CLR 6 \"4.2\" \"_Toc311798019\"]\n\t\t, syntax_examples = map (EXs \"Function\" \"macro\") [\"f :: \" <+ lista <+ \" -> a\", \"ints = \" <+ listints]\n\t\t})\n\twhere\n\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\tkind = case k of\n\t\t\t[] -> \" normal\"\n\t\t\t['#'] -> \"n unboxed\"\n\t\t\t['!'] -> \" head strict\"\n\t\t\t['|'] -> \"n overloaded\"\n\t\tspine = case s of\n\t\t\t[] -> \"\"\n\t\t\t['!'] -> \" spine strict\"\n\n\t\tdescription = \"These types of list are available:\\n\" +\n\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\nbs_macro = ([\":==\", \"macro\"],\n\t{ syntax_title = \"macro\"\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_location = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t})\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_location = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_location = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_location = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_location = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_location = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_tuples = [make_tuple n \\\\ n <- [1..31]]\nwhere\n\tmake_tuple :: Int -> ([SyntaxPattern], SyntaxEntry)\n\tmake_tuple n = ([toString ['(':repeatn n ','++[')']], withargs, \"tuple\"],\n\t\t{ syntax_title = ary + \"ary tuple\"\n\t\t, syntax_code = [withvars]\n\t\t, syntax_description =\n\t\t\t\"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\" +\n\t\t\t\"Clean supports tuples of arity 2 to 32.\"\n\t\t, syntax_doc_location = [CLR 6 \"4.3\" \"_Toc311798026\"]\n\t\t, syntax_examples = []\n\t\t})\n\twhere\n\t\twithargs = toString ['(\\\\w':foldl (++) [] [[',\\\\w'] \\\\ _ <- [1..n]] ++ [')']]\n\t\twithvars = toString ['(a' :foldl (++) [] [[',':v] \\\\ _ <- [1..n] & v <- map (\\x->[x]) ['b'..'z'] ++ [[v,'`'] \\\\ v <- ['a'..]]] ++ [')']]\n\t\tary = case n of\n\t\t\t1 -> \"bin\"\n\t\t\t2 -> \"tren\"\n\t\t\tn -> n+1 <+ \"-\"\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code = [\"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements\"\n\t, syntax_doc_location = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code = [\"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields\"\n\t, syntax_doc_location = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_location = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_location = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_location = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_location = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n","old_contents":"implementation module BuiltinSyntax\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nimport Data.Maybe\nimport Text\n\nimport Cloogle\nimport CloogleDB\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t bs_arrays ++\n\t[ bs_case\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_import\n\t, bs_infix\n\t, bs_let\n\t, bs_let_before\n\t] ++ bs_lists ++\n\t[ bs_module\n\t, bs_otherwise\n\t\/\/ TODO bs_selection (arrays and records)\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t] ++ bs_tuples ++\n\t[ bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t\/\/ TODO bs_zf\n\t]\n\nCLR :: Int String String -> SyntaxDocLocation\nCLR f sec h = CleanLangReport\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_arrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\nwhere\n\tmake_array :: [Char] -> ([SyntaxPattern], SyntaxEntry)\n\tmake_array k = ([\"array\", typec, toString (['{':k]++['\\\\w}'])],\n\t\t{ syntax_title = kind + \"array\"\n\t\t, syntax_code = [typec]\n\t\t, syntax_description = \"An array contains a finite number of elements of the same type. Access time is constant.\"\n\t\t, syntax_doc_location = [CLR 6 \"4.4\" \"_Toc311798029\"]\n\t\t, syntax_examples = [EX \"Function\" (\"xs :: {\" <+ k <+ \"Int}\\nxs = {\" <+ k <+ \"1,3,6,10}\")]\n\t\t})\n\twhere\n\t\ttypec = toString (['{':k]++['}'])\n\t\tkind = case k of\n\t\t\t[] -> \"\"\n\t\t\t['!'] -> \"strict \"\n\t\t\t['#'] -> \"unboxed \"\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_location = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_location = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_location = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_location = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_location = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_location = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_location = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_location = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_location = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_location = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_lists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\nwhere\n\tmake_list :: [Char] [Char] -> ([SyntaxPattern], SyntaxEntry)\n\tmake_list k s = ([higherorder, listany, \"list\"],\n\t\t{ syntax_title = \"lists\"\n\t\t, syntax_code = [higherorder]\n\t\t, syntax_description = \"A\" + kind + spine + \" list.\\n\\n\" + description\n\t\t, syntax_doc_location = [CLR 6 \"4.2\" \"_Toc311798019\"]\n\t\t, syntax_examples = map (EXs \"Function\" \"macro\") [\"f :: \" <+ lista <+ \" -> a\", \"ints = \" <+ listints]\n\t\t})\n\twhere\n\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\tkind = case k of\n\t\t\t[] -> \" normal\"\n\t\t\t['#'] -> \"n unboxed\"\n\t\t\t['!'] -> \" head strict\"\n\t\t\t['|'] -> \"n overloaded\"\n\t\tspine = case s of\n\t\t\t[] -> \"\"\n\t\t\t['!'] -> \" spine strict\"\n\n\t\tdescription = \"These types of list are available:\\n\" +\n\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_location = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"definition module ...\"\n\t\t, EX \"Function\" \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, EX \"Function\" \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, EX \"Function\" \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, EX \"Function\" \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_location = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_location = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_location = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_location = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_tuples = [make_tuple n \\\\ n <- [1..31]]\nwhere\n\tmake_tuple :: Int -> ([SyntaxPattern], SyntaxEntry)\n\tmake_tuple n = ([toString ['(':repeatn n ','++[')']], withargs, \"tuple\"],\n\t\t{ syntax_title = ary + \"ary tuple\"\n\t\t, syntax_code = [withvars]\n\t\t, syntax_description =\n\t\t\t\"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\" +\n\t\t\t\"Clean supports tuples of arity 2 to 32.\"\n\t\t, syntax_doc_location = [CLR 6 \"4.3\" \"_Toc311798026\"]\n\t\t, syntax_examples = []\n\t\t})\n\twhere\n\t\twithargs = toString ['(\\\\w':foldl (++) [] [[',\\\\w'] \\\\ _ <- [1..n]] ++ [')']]\n\t\twithvars = toString ['(a' :foldl (++) [] [[',':v] \\\\ _ <- [1..n] & v <- map (\\x->[x]) ['b'..'z'] ++ [[v,'`'] \\\\ v <- ['a'..]]] ++ [')']]\n\t\tary = case n of\n\t\t\t1 -> \"bin\"\n\t\t\t2 -> \"tren\"\n\t\t\tn -> n+1 <+ \"-\"\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code = [\"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements\"\n\t, syntax_doc_location = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code = [\"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields\"\n\t, syntax_doc_location = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_location = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_location = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_location = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_location = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"a8b76fa880e8372863214bde89a8b2f31a238ba6","subject":"Fix distance for macro search","message":"Fix distance for macro search\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , distance :: Int\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , generic_derivations :: Maybe [String]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [String]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,modules,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_INVALIDNAME \"function name too long\", w)\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= (err E_INVALIDNAME \"name cannot contain spaces\", w)\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= (err E_INVALIDTYPE \"couldn't parse type\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,page} db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= map (uncurry (makeTypeResult (Just typeName))) types\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t , isModMatchF <$> modules\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case name of\n\t\t\tNothing = []\n\t\t\t(Just n) = findMacro` (\\(ML lib mod m) _ -> isNameMatch (size n-2) n (FL lib mod m)) db\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (CL lib mod _) _ _ f _ -> isNameMatch\n\t\t (size n-2) n (FL lib mod f)) <$> name\n\t\t , isModMatchC <$> modules\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcTypeName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case lcTypeName of\n\t\t\t(Just n) = findType` (\\(TL _ _ t) _ -> toLowerCase t == n) db\n\t\t\tNothing = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = map (flip makeClassResult db) $\n\t\t\t\tfindClass` (\\(CL _ _ c`) _ _ _ -> toLowerCase c` == c) db\n\t\t\t_ = []\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (ClassLocation, [TypeVar], ClassContext, [(FunctionName,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult (CL lib mod cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t }\n\t\t , { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t\t if (isEmpty cc) \"\" \" \" + concat (print False cc)\n\t\t , class_funs = [concat $ print False fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sort [concat (print False t) \\\\ t <- getInstances cls db]\n\t\t }\n\t\t )\n\n\tmakeTypeResult :: (Maybe String) TypeLocation TypeDef -> Result\n\tmakeTypeResult mbName (TL lib mod t) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) MacroLocation Macro -> Result\n\tmakeMacroResult mbName (ML lib mod m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t (FunctionLocation, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (FL lib mod fname, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t }\n\t\t , { func = concat $ print False (fname,et)\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t\t, constructor_of = if (tes.te_isconstructor)\n\t\t\t\t(let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t\t\tNothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t\t (\\_ -> [concat $ print False d \\\\ d <-derivs]) <$>\n\t\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= toInt $ sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)]\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= levenshtein` orgsearch fname\n\t\twhere\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein a b\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatchF :: ![String] FunctionLocation ExtendedType -> Bool\n\tisModMatchF mods (FL _ mod _) _ = isMember mod mods\n\n\tisModMatchC :: ![String] ClassLocation [TypeVar] ClassContext FunctionName ExtendedType -> Bool\n\tisModMatchC mods (CL _ mod _) _ _ _ _ = isMember mod mods\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg +\n\t\t\tif (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\" + \")\\n\"\n\tmsgToString _ _ = \"\"\n","old_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , distance :: Int\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , generic_derivations :: Maybe [String]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [String]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,modules,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_INVALIDNAME \"function name too long\", w)\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= (err E_INVALIDNAME \"name cannot contain spaces\", w)\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= (err E_INVALIDTYPE \"couldn't parse type\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,page} db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= map (uncurry (makeTypeResult (Just typeName))) types\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t , isModMatchF <$> modules\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case name of\n\t\t\tNothing = []\n\t\t\t(Just n) = findMacro` (\\(ML lib mod m) _ -> isNameMatch (size n-2) n (FL lib mod m)) db\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (CL lib mod _) _ _ f _ -> isNameMatch\n\t\t (size n-2) n (FL lib mod f)) <$> name\n\t\t , isModMatchC <$> modules\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcTypeName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case lcTypeName of\n\t\t\t(Just n) = findType` (\\(TL _ _ t) _ -> toLowerCase t == n) db\n\t\t\tNothing = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = map (flip makeClassResult db) $\n\t\t\t\tfindClass` (\\(CL _ _ c`) _ _ _ -> toLowerCase c` == c) db\n\t\t\t_ = []\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (ClassLocation, [TypeVar], ClassContext, [(FunctionName,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult (CL lib mod cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t }\n\t\t , { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t\t if (isEmpty cc) \"\" \" \" + concat (print False cc)\n\t\t , class_funs = [concat $ print False fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sort [concat (print False t) \\\\ t <- getInstances cls db]\n\t\t }\n\t\t )\n\n\tmakeTypeResult :: (Maybe String) TypeLocation TypeDef -> Result\n\tmakeTypeResult mbName (TL lib mod t) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) MacroLocation Macro -> Result\n\tmakeMacroResult mbName (ML lib mod m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` m (fromJust mbName))\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t (FunctionLocation, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (FL lib mod fname, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t }\n\t\t , { func = concat $ print False (fname,et)\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t\t, constructor_of = if (tes.te_isconstructor)\n\t\t\t\t(let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t\t\tNothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t\t (\\_ -> [concat $ print False d \\\\ d <-derivs]) <$>\n\t\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= toInt $ sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)]\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= levenshtein` orgsearch fname\n\t\twhere\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein a b\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatchF :: ![String] FunctionLocation ExtendedType -> Bool\n\tisModMatchF mods (FL _ mod _) _ = isMember mod mods\n\n\tisModMatchC :: ![String] ClassLocation [TypeVar] ClassContext FunctionName ExtendedType -> Bool\n\tisModMatchC mods (CL _ mod _) _ _ _ _ = isMember mod mods\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg +\n\t\t\tif (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\" + \")\\n\"\n\tmsgToString _ _ = \"\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"cef762307e7f18b0619fe44f2b2357f17aa46e76","subject":"Fix documentation of ccall","message":"Fix documentation of ccall\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/ABC.icl","new_file":"backend\/Builtin\/ABC.icl","new_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t, i_push_a_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\ti_push_a_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a_b\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET]\n\t\t, aie_description = \"Pushes the A-stack element as an integer (i.e., a pointer to the heap) on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t, i_push_r_arg_t\n\t, i_push_t_r_a\n\t, i_push_t_r_args\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html.\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \" - `sep` can be either `-` or `:`.\"\n\t\t\t, \" - `flags` can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \" - `input` is a number of input argument types (allowed: `IpRrSsAOF`; see below).\"\n\t\t\t, \" - `output` is a number of output argument types (allowed: `VIpRrSsAOF`; see below).\"\n\t\t\t, \" - `state` is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \" - `I` for integers\"\n\t\t\t, \" - `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \" - [`Rr`] for reals\"\n\t\t\t, \" - `S` for Clean Strings (`{#Char}`). If used as input type this passes a pointer to the string's length (number of characters). The actual array is at offset 4\/8 (32\/64 bit). If this is used as output type, the C function has to return a pointer to the string's length, followed by the actual string. A copy of the string will be created in the Clean heap, and this copy will be used by Clean. If the string was allocated in C, for example using malloc, it should be deallocated in C when it is no longer used.\"\n\t\t\t, \" - `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}}, as the string is not null-terminated). The length (number of characters) is at offset -4\/-8. (32\/64 bit).\"\n\t\t\t, \" - `A` for A-stack elements. A pointer to the third block of the node is passed. For arrays, this is a pointer to the elements. One word higher is the element type. The size of the array is two words higher.\"\n\t\t\t, \" - [`OF`] for function pointers\"\n\t\t\t, \" - `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\n\ti_push_r_arg_t =\n\t\t{ zero\n\t\t& aie_instruction = \"push_r_arg_t\"\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Gets the *n*th element from the type string of a record.\"\n\t\t\t, \"The type string is on top of the B-stack; *n* below that.\"\n\t\t\t]\n\t\t}\n\ti_push_t_r_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Push the address of the type string of the referenced record to the B-stack.\"\n\t\t}\n\ti_push_t_r_args =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_args\"\n\t\t, aie_description = \"Pops a record from the A-stack, pushes its members in reversed order to both of the stacks, then pushes the address of the type string to the B-stack.\"\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_n\n\t, d_nu\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_n =\n\t\t{ zero\n\t\t& aie_instruction = \".n\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t, \"\\n\\nThere are some special cases:\\n\\n\"\n\t\t\t, \"- An arity of `-1` is for tuple selectors;\\n\"\n\t\t\t, \"- An arity of `-2` is for indirection nodes;\\n\"\n\t\t\t, \"- An arity of `-3` is for record selectors of basic types;\\n\"\n\t\t\t, \"- An arity of `-4` is for record selectors of non-basic types.\\n\\n\"\n\t\t\t, \"See also {{`.nu`}}.\"\n\t\t\t]\n\t\t}\n\td_nu =\n\t\t{ zero\n\t\t& aie_instruction = \".nu\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels with arguments on the B-stack (otherwise, {{`.n`}} is used).\"\n\t\t\t, \"The first integer is the number of A-stack arguments; the second the number of B-stack arguments.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","old_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t, i_push_a_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\ti_push_a_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a_b\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET]\n\t\t, aie_description = \"Pushes the A-stack element as an integer (i.e., a pointer to the heap) on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t, i_push_r_arg_t\n\t, i_push_t_r_a\n\t, i_push_t_r_args\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \" - sep can be either `-` or `:`.\"\n\t\t\t, \" - flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \" - input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t\t, \" - output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t\t, \" - state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \" - `I` for integers\"\n\t\t\t, \" - `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \" - [`Rr`] for reals\"\n\t\t\t, \" - `S` for Clean Strings (`{#Char}`). If used as input type this passes a pointer to the string's length (number of characters). The actual array is at offset 4\/8 (32\/64 bit). If this is used as output type, the C function has to return a pointer to the string's length, followed by the actual string. A copy of the string will be created in the Clean heap, and this copy will be used by Clean. If the string was allocated in C, for example using malloc, it should be deallocated in C when it no longer used, it is not automatically deallocated by Clean.\"\n\t\t\t, \" - `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}}, as the string is not null-terminated). The length (number of characters) is at offset -4\/-8. (32\/64 bit).\"\n\t\t\t, \" - `A` for A-stack elements. A pointer to the third block of the node is passed. For arrays, this is a pointer to the elements. The size of the array is one word higher in the block.\"\n\t\t\t, \" - [`OF`] for function pointers\"\n\t\t\t, \" - `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\n\ti_push_r_arg_t =\n\t\t{ zero\n\t\t& aie_instruction = \"push_r_arg_t\"\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Gets the *n*th element from the type string of a record.\"\n\t\t\t, \"The type string is on top of the B-stack; *n* below that.\"\n\t\t\t]\n\t\t}\n\ti_push_t_r_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Push the address of the type string of the referenced record to the B-stack.\"\n\t\t}\n\ti_push_t_r_args =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_args\"\n\t\t, aie_description = \"Pops a record from the A-stack, pushes its members in reversed order to both of the stacks, then pushes the address of the type string to the B-stack.\"\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_n\n\t, d_nu\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_n =\n\t\t{ zero\n\t\t& aie_instruction = \".n\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t, \"\\n\\nThere are some special cases:\\n\\n\"\n\t\t\t, \"- An arity of `-1` is for tuple selectors;\\n\"\n\t\t\t, \"- An arity of `-2` is for indirection nodes;\\n\"\n\t\t\t, \"- An arity of `-3` is for record selectors of basic types;\\n\"\n\t\t\t, \"- An arity of `-4` is for record selectors of non-basic types.\\n\\n\"\n\t\t\t, \"See also {{`.nu`}}.\"\n\t\t\t]\n\t\t}\n\td_nu =\n\t\t{ zero\n\t\t& aie_instruction = \".nu\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels with arguments on the B-stack (otherwise, {{`.n`}} is used).\"\n\t\t\t, \"The first integer is the number of A-stack arguments; the second the number of B-stack arguments.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"d71b1850b5a4a04236158df7b79084dd24a95bdc","subject":"Copy editing","message":"Copy editing\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \"[\", \"]\", \".\", \":\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:... | [...<=...]\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [...<=...]`).\"\n\t\t, \"\\n\\nNote that when using unique types in a function or an ADT the container must also be unique.\"\n\t\t, \"For instance, `T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"\\n\\nFunctions have to be split up into arity 1 and the sub functions need to be annotated as well.\"\n\t\t, \"For instance, `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \"[\", \"]\", \".\", \":\"]\n\t, syntax_code =\n\t\t[\"*...\"\n\t\t,\". ...\" \n\t\t,\"v:.. | [v ..]\" \n\t\t]\n\t, syntax_description = \"Annotates a type with its uniqueness. A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [..]`). Note that when using unique types in a function or an ADT the container must also be unique. e.g. `T = T (Int, *File)` has to be `T = T *(Int, *File)`. Functions have to be split up into arity 1 and the sub functions need to be annotated as well. e.g. `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/World is unique\"\n\t\t, \"f :: .a -> .a \/\/f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"ccb507f87256146a53f3e34a2ee9d1e2df3c5659","subject":"Split up named patterns and pattern predicates in Builtin.Syntax","message":"Split up named patterns and pattern predicates in Builtin.Syntax\n","repos":"dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \".\", \"%:\", \"[*<=*]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs. This can also be used to check if a value (not a function argument) matches a pattern (undocumented and you can not use identifiers). `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t, EX \"isSingleton l = l =: [_] \/\/Match a value with a pattern\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \".\", \"%:\", \"[*<=*]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"0950efb7a1318077b252a4127a8d9ae7a73abbb5","subject":"EXPERIMENTAL: Forking for concurrent request handling (#17)","message":"EXPERIMENTAL: Forking for concurrent request handling (#17)\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"SimpleTCPServer.icl","new_file":"SimpleTCPServer.icl","new_contents":"implementation module SimpleTCPServer\n\nimport TCPIP\nimport StdEnv\nimport StdMaybe\nimport System._Posix\n\ninstance zero (Logger a b s) where zero = \\_ _ w -> (undef, w)\n\nserve :: (a *World -> *(b,*World)) (Maybe (Logger a b s)) Port *World -> *World | fromString a & toString b\nserve f log port w\n# (ok, mbListener, w) = openTCP_Listener port w\n| not ok = abort (\"Couldn't open port \" +++ toString port)\n# listener = fromJust mbListener\n# log = if (isNothing log) zero (fromJust log)\n# (listener, w) = handle f log listener w\n= closeRChannel listener w\nwhere\n handle :: (a *World -> *(b,*World)) (Logger a b s) TCP_Listener *World\n -> (TCP_Listener, *World) | fromString a & toString b\n handle f log li w\n # ((ip, dupChan),li,w) = receive li w\n\t# (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t\/\/ Parent: handle new requests\n\t| pid > 0 = handle f log li w\n\t\/\/ Child: handle current request\n #! (s, w) = log (Connected ip) undef w\n #! (msg, rChan, w) = receive dupChan.rChannel w\n dupChan = {dupChan & rChannel=rChan}\n #! msg = fromString (toString msg)\n #! (s, w) = log (Received msg) s w\n #! (resp, w) = f msg w\n #! (sChan, w) = send (toByteSeq (toString resp)) dupChan.sChannel w\n dupChan = {dupChan & sChannel=sChan}\n #! (s, w) = log (Sent resp) s w\n #! w = closeRChannel dupChan.rChannel w\n #! w = closeChannel dupChan.sChannel w\n #! (s, w) = log Disconnected s w\n\t= exit 0 w\n","old_contents":"implementation module SimpleTCPServer\n\nimport TCPIP\nimport StdEnv\nimport StdMaybe\n\ninstance zero (Logger a b s) where zero = \\_ _ w -> (undef, w)\n\nserve :: (a *World -> *(b,*World)) (Maybe (Logger a b s)) Port *World -> *World | fromString a & toString b\nserve f log port w\n# (ok, mbListener, w) = openTCP_Listener port w\n| not ok = abort (\"Couldn't open port \" +++ toString port)\n# listener = fromJust mbListener\n# log = if (isNothing log) zero (fromJust log)\n# (listener, w) = handle f log listener w\n= closeRChannel listener w\nwhere\n handle :: (a *World -> *(b,*World)) (Logger a b s) TCP_Listener *World\n -> (TCP_Listener, *World) | fromString a & toString b\n handle f log li w\n # ((ip, dupChan),li,w) = receive li w\n # (s, w) = log (Connected ip) undef w\n # (msg, rChan, w) = receive dupChan.rChannel w\n dupChan = {dupChan & rChannel=rChan}\n # msg = fromString (toString msg)\n # (s, w) = log (Received msg) s w\n # (resp, w) = f msg w\n # (sChan, w) = send (toByteSeq (toString resp)) dupChan.sChannel w\n dupChan = {dupChan & sChannel=sChan}\n # (s, w) = log (Sent resp) s w\n # w = closeRChannel dupChan.rChannel w\n # w = closeChannel dupChan.sChannel w\n # (s, w) = log Disconnected s w\n = handle f log li w\n\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"265a503117c9944185fd54d4d9c64cf202b55df3","subject":"Use normalised requests as cache key (parsed types, sorted lists)","message":"Use normalised requests as cache key (parsed types, sorted lists)\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nimport StdList\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Tuple\nimport Data.Maybe\nimport System.CommandLine\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\nimport Text.JSON\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\nimport Cloogle\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe ([String], Bool)\n\t , c_page :: Maybe Int\n\t }\n\nderive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = appFst sort <$> r.libraries\n\t, c_page = r.page\n\t}\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle _ Nothing w = (err CLOOGLE_E_INVALIDINPUT \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache request w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey request, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err CLOOGLE_E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err CLOOGLE_E_NORESULTS \"No results\")\n\t\t\t{ return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: Response *World -> *(Response, CacheKey, *World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: Int Int Response [Result] *World -> *World\n\t\tcachePages _ _ _ [] w = w\n\t\tcachePages 0 _ _ _ w = w\n\t\tcachePages npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = ((+) i) <$> (key.c_page <|> pure 0) }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n (Location lib mod Nothing Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line iclline cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line iclline f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\loc _ _ _ -> toLowerCase (getName loc) == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line iclline cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" | \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [([concat (print False t) \\\\ t <- ts], map loc ls)\n\t\t \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line iclline t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line iclline m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,iclline,builtin) = case fl of\n\t\t\t(Location l m ln iln f) = (l, m, f, ln, iln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln iln _) = (lib, mod, ln, iln)\n\n\tlog :: (LogMessage (Maybe Request) Response CacheKey) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _ _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available} ck) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg\n\t\t\t+ if (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\"\n\t\t\t+ \"; cache: \" + ck + \")\\n\"\n\tmsgToString _ _ = \"\"\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nimport StdList\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Tuple\nimport Data.Maybe\nimport System.CommandLine\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\nimport Cloogle\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle _ Nothing w = (err CLOOGLE_E_INVALIDINPUT \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache request w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey request, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err CLOOGLE_E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err CLOOGLE_E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err CLOOGLE_E_NORESULTS \"No results\")\n\t\t\t{ return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\trespond :: Response *World -> *(Response, CacheKey, *World)\n\t\trespond r w = (r, cacheKey request, writeCache LongTerm request r w)\n\n\t\tcachePages :: Int Int Response [Result] *World -> *World\n\t\tcachePages _ _ _ [] w = w\n\t\tcachePages 0 _ _ _ w = w\n\t\tcachePages npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { request & page = ((+) i) <$> (request.page <|> pure 0) }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n (Location lib mod Nothing Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line iclline cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line iclline f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\loc _ _ _ -> toLowerCase (getName loc) == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line iclline cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" | \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [([concat (print False t) \\\\ t <- ts], map loc ls)\n\t\t \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line iclline t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line iclline m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = iclline\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,iclline,builtin) = case fl of\n\t\t\t(Location l m ln iln f) = (l, m, f, ln, iln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln iln _) = (lib, mod, ln, iln)\n\n\tlog :: (LogMessage (Maybe Request) Response CacheKey) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _ _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available} ck) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg\n\t\t\t+ if (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\"\n\t\t\t+ \"; cache: \" + ck + \")\\n\"\n\tmsgToString _ _ = \"\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"bac25515f111115ec1cd3fd44d9cf857c23e340f","subject":"update gen","message":"update gen\n","repos":"clean-cloogle\/clean-irc","old_file":"IRC.icl","new_file":"IRC.icl","new_contents":"implementation module IRC\n\nimport StdGeneric\nimport StdList\nimport StdTuple\nimport GenPrint\nimport GenBimap\nimport StdOverloaded\nimport Data.Maybe\nimport Data.Either\nimport StdFunc\nimport StdString\nimport StdChar\nimport StdBool\nimport _SystemArray\n\nimport Text.Parsers.Simple.Core\nimport Text.Parsers.Simple.Chars\nimport Data.Tuple\nimport Control.Monad\nimport Control.Applicative\nfrom Data.Functor import <$>\n\nfrom Data.Func import $\nfrom Text import class Text(ltrim,indexOf,concat), instance Text String\nimport qualified Text\nfrom StdMisc import undef\nimport StdDebug\n\njon :== 'Text'.join\n\nderive gPrint IRCCommand, IRCReplies, IRCErrors, (,), Maybe, (), Either, IRCMessage, IRCUser, IRCNumReply\n\nStart = jon \"\\n\" $ map printToString\n\t[ parseIRCMessage \":clooglebot!~cloogle@dhcp-077-249-221-037.chello.nl QUIT\\r\\n\"\n\t, parseIRCMessage \":clooglebot!~cloogle QUIT\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 QUIT\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY test\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY :test with spaces\\r\\n\"\n\t, parseIRCMessage \":cherryh.freenode.net NOTICE * :*** Found your hostname\\r\\n\"\n\t, parseIRCMessage \":cherryh.freenode.net QUIT :hoi hoi\\r\\n\"\n\t]\n\n(<+) infixr 5 :: a b -> String | toString a & toString b\n(<+) a b = toString a +++ toString b\n\nparseIRCMessage :: String -> Either [Error] IRCMessage\nparseIRCMessage s = case runParser parsePrefix (fromString s) of\n\t([(prefix, rest):_], _)\n\t\t= case parse parseReply rest of\n\t\t\tLeft e = case parseCmd rest of\n\t\t\t\tLeft e2 = Left $ e2 ++ e\n\t\t\t\tRight cmd = Right {IRCMessage | irc_prefix=prefix, irc_command=Right cmd}\n\t\t\tRight repl = Right {IRCMessage | irc_prefix=prefix, irc_command=Left repl}\n\t(_, es) = Left [\"couldn't parse prefix\":es]\n\nparsePrefix :: Parser Char (Maybe (Either IRCUser String))\nparsePrefix = optional (pToken ':' >>| parseEither parseUser parseHost) <* pToken ' '\n\ngeneric gIRCParse a :: [String] -> (Either [Error] a, [String])\ngIRCParse{|UNIT|} a = (Right UNIT, a)\ngIRCParse{|String|} [a:as] = (Right a, as)\ngIRCParse{|String|} [] = (Left [\"Expected a string\"], [])\ngIRCParse{|Int|} [a:as] = (Right $ toInt a, as)\ngIRCParse{|Int|} [] = (Left [\"Expected an integer\"], [])\ngIRCParse{|EITHER|} lp rp as = case lp as of\n\t(Right a, rest) = (Right $ LEFT a, rest)\n\t(Left e1, rest) = case rp as of\n\t\t(Right a, rest) = (Right $ RIGHT a, rest)\n\t\t(Left e2, rest) = (Left $ e1 ++ e2, [])\ngIRCParse{|OBJECT|} p as = case p as of\n\t(Right e, rest) = (Right $ OBJECT e, rest)\n\t(Left e, rest) = (Left e, [])\ngIRCParse{|CONS of d|} p [] = (Left [\"Expected a cmd constructor: \" +++ d.gcd_name], [])\ngIRCParse{|CONS of d|} p [a:as]\n| a <> d.gcd_name = (Left [\"Wrong constructor. expected: \" +++ d.gcd_name +++ \", got: \" +++ a], [])\n= case p as of\n\t(Right a, rest) = (Right $ CONS a, rest)\n\t(Left e, rest) = (Left e, [])\ngIRCParse{|PAIR|} pl pr as = case pl as of\n\t(Right a1, rest) = case pr rest of\n\t\t(Right a2, rest) = (Right $ PAIR a1 a2, rest)\n\t\t(Left e, rest) = (Left e, [])\n\t(Left e, rest) = (Left e, [])\ngIRCParse{|[]|} pl as = plist pl as\nwhere\n\tplist pl as = case pl as of\n\t\t(Right e, rest) = case plist pl rest of\n\t\t\t(Right es, rest) = (Right [e:es], rest)\n\t\t\t(Left e, rest) = (Left e, [])\n\t\t(Left e, rest) = (Right [], as)\ngIRCParse{|Maybe|} pm as = case pm as of\n\t(Right a, rest) = (Right $ Just a, rest)\n\t(Left e, rest) = (Right Nothing, as)\n\nderive gIRCParse (,), (,,), IRCCommand\n\nparseCmd :: [Char] -> Either [Error] IRCCommand\nparseCmd cs = fst $ gIRCParse{|*|} $ argfun $ 'Text'.split \" \" $ toString cs\n\/\/= parse cmdParser $ argfun $ 'Text'.split \" \" $ toString cs\n\twhere\n\t\targfun :: [String] -> [String]\n\t\targfun [] = []\n\t\targfun [x:xs]\n\t\t# x = 'Text'.trim x\n\t\t| x.[0] == ':' = [jon \" \" $ [x:map 'Text'.rtrim xs]]\n\t\t| otherwise = [x:argfun xs]\n\n\t\tp = pSatisfy (const True)\n\t\tlst = fmap $ 'Text'.split \",\"\n\t\topt = optional p\n\t\tpInt = toInt <$> p\n\n\t\tnn p f = pToken p >>| f\n\n\t\tcmdParser :: Parser String IRCCommand\n\t\tcmdParser =\n\t\t\t (nn \"ADMIN\" $ fmap ADMIN opt)\n\t\t\t<|> (nn \"AWAY\" $ fmap AWAY p)\n\t\t\t<|> (nn \"CONNECT\" $ liftM2 CONNECT p (optional $ liftM2 tuple pInt opt))\n\t\t\t<|> (nn \"DIE\" $ pure DIE)\n\t\t\t<|> (nn \"ERROR\" $ fmap ERROR p)\n\t\t\t<|> (nn \"INFO\" $ fmap INFO opt)\n\t\t\t<|> (nn \"INVITE\" $ liftM2 INVITE p p)\n\t\t\t<|> (nn \"ISON\" $ fmap ISON $ pMany p)\n\/\/\t\t\t<|> (nn \"JOIN\" $ fmap JOIN $ lst p >>= \\ch->lst p >>= \\ks->pure (zip2 ch (ks ++ repeat Nothing)))\n\t\t\t<|> (nn \"KICK\" $ liftM3 KICK p p opt)\n\t\t\t<|> (nn \"KILL\" $ liftM2 KILL p p)\n\t\t\t<|> (nn \"LINKS\" $ fmap LINKS $ optional $ liftM2 tuple opt p)\n\t\t\t<|> (nn \"LIST\" $ fmap LIST $ optional $ liftM2 tuple ('Text'.split \",\" <$> p) opt)\n\t\t\t<|> (nn \"LUSERS\" $ fmap LUSERS $ optional $ liftM2 tuple p opt)\n\t\t\t<|> (nn \"MODE\" $ liftM5 MODE p p opt opt opt)\n\t\t\t<|> (nn \"MOTD\" $ fmap MOTD $ opt)\n\t\t\t<|> (nn \"NAMES\" $ fmap NAMES $ lst p)\n\t\t\t<|> (nn \"NICK\" $ fmap NAMES $ lst p)\n\t\t\t\/\/\"NICK\" = String (Maybe String)\n\t\t\t\/\/\"NJOIN\" = command0 NJOIN args\n\t\t\t\/\/\"NOTICE\" = String String\n\t\t\t\/\/\"OPER\" = String String \n\t\t\t\/\/\"PART\" = [String]\n\t\t\t\/\/\"PASS\" = String\n\t\t\t\/\/\"PING\" = String (Maybe String)\n\t\t\t\/\/\"PONG\" = String (Maybe String)\n\t\t\t\/\/\"PRIVMSG\" = [String] String\n\/\/\t\t\t\"QUIT\" = case args of\n\/\/\t\t\t\t[_,_:_] = Left $ \"QUIT has too many arguments\"\n\/\/\t\t\t\tx = Right $ QUIT $ listToMaybe x\n\/\/\t\t\t\"REHASH\" = command0 REHASH args\n\/\/\t\t\t\"RESTART\" = command0 REHASH args\n\/\/\t\t\t\"SERVER\" = command0 REHASH args\n\t\t\t\/\/\"SERVICE\" = String String String String\n\t\t\t\/\/\"SERVLIST\" = (Maybe (String, Maybe String))\n\t\t\t\/\/\"SQUERY\" = String String\n\/\/\t\t\t\"SQUIRT\" = command0 REHASH args\n\t\t\t\/\/\"SQUIT\" = String String\n\t\t\t\/\/\"STATS\" = (Maybe (String, Maybe String))\n\t\t\t\/\/\"SUMMON\" = String (Maybe (String, Maybe String))\n\t\t\t\/\/\"TIME\" = (Maybe String)\n\t\t\t\/\/\"TOPIC\" = String (Maybe String)\n\t\t\t\/\/\"TRACE\" = (Maybe String)\n\t\t\t\/\/\"USER\" = String String String\n\t\t\t\/\/\"USERHOST\" = [String]\n\t\t\t\/\/\"USERS\" = (Maybe String)\n\t\t\t\/\/\"VERSION\" = (Maybe String)\n\t\t\t\/\/\"WALLOPS\" = String\n\t\t\t\/\/\"WHO\" = (Maybe String)\n\t\t\t\/\/\"WHOIS\" = (Maybe String) [String]\n\t\t\t\/\/\"WHOWAS\" = (Maybe String) [String]\n\nparseReply :: Parser Char IRCNumReply\nparseReply = (toString <$> pSome pDigit)\n\t>>= \\rep->pMiddle\n\t>>= \\recipient->spaceParser >>| (toString <$> pSome (pNoneOf illegal))\n\t>>= \\msg->pure {IRCNumReply|irc_reply=fs rep,irc_recipient=recipient,irc_message=msg}\n\twhere\n\t\tfs :: String -> IRCReplies\n\t\tfs s = fromInt $ toInt s\n\nspaceParser :: Parser Char [Char]\nspaceParser = pMany $ pToken ' '\n\nparseServer :: Parser Char String\nparseServer = pFail\n\nparseEither :: (Parser a b) (Parser a c) -> Parser a (Either b c)\nparseEither p q = Left <$> p <|> Right <$> q\n\nparseUser :: Parser Char IRCUser\nparseUser = parseNick\n\t\t>>= \\nick->optional (pToken '!' >>| parseUsr)\n\t\t>>= \\muser->optional (pToken '@' >>| parseHost)\n\t\t>>= \\mhost->pure {IRCUser | irc_nick=nick, irc_user=muser, irc_host=mhost}\n\nparseUsr :: Parser Char String\nparseUsr = toString <$> pSome (pNoneOf [' ', '@':illegal])\n\nparseNick :: Parser Char String\nparseNick = pAlpha >>= \\c->pMany (pAlpha <|> pDigit <|> pSpecial)\n\t>>= \\cs->pure (toString [c:cs])\n\npSpecial :: Parser Char Char\npSpecial = pOneOf ['-', '[', ']', '\\\\', '\\`', '^', '{', '}']\n\nparseHost :: Parser Char String\nparseHost = jon \".\" <$> pSepBy parseName (pToken '.')\n\twhere\n\t\tparseName :: Parser Char String\n\t\tparseName = toString <$> pSome (pAlpha <|> pDigit <|> pOneOf ['-'])\n\ninstance toString IRCNumReply where\n\ttoString m = toInt m.irc_reply <+ \" \" <+ m.irc_recipient <+ \" \" <+ formatMSG m.irc_message\ninstance toString IRCMessage where\n\ttoString m = maybe \"\" (\\s->either ((<+) \":\") id s <+ \" \") m.irc_prefix\n\t\t<+ either toString toString m.irc_command\n\ninstance toString IRCUser where\n\ttoString m = m.irc_nick <+ maybe \"\" ((<+) \"!\") m.irc_user\n\t\t<+ maybe \"\" ((<+) \"@\") m.irc_host\n\ncons :: a [a] -> [a]\ncons a as = [a:as]\n\npMiddle :: Parser Char String\npMiddle = fmap toString $\n\tspaceParser >>| liftM2 cons (pNotSatisfy ((==)':')) (pMany $ pNoneOf [' ':illegal])\n\npTrailing :: Parser Char String\npTrailing = fmap toString $ \n\tspaceParser >>| pToken ':' >>| pMany (pNoneOf illegal)\n\npParam :: Parser Char String\npParam = pMiddle <|> pTrailing\n\npNoneOf :: [a] -> Parser a a | Eq a\npNoneOf l = pSatisfy (not o flip isMember l)\n\npNotSatisfy :: (a -> Bool) -> Parser a a | Eq a\npNotSatisfy f = pSatisfy (not o f)\n\npInt :: Parser Char Int\npInt = toInt o toString <$> (spaceParser >>| pSome pDigit)\n\nillegal :: [Char]\nillegal = ['\\x00','\\r','\\n']\n\ninstance toString IRCCommand where\n\ttoString r = jon \" \" (print r) +++ \"\\r\\n\"\n\nprint :: IRCCommand -> [String]\nprint r = case r of\n\t\tADMIN mm = [\"ADMIN\":maybeToList mm]\n\t\tAWAY m = [\"AWAY\",m]\n\t\/\/CONNECT String (Maybe (Int, Maybe String))\n\t\/\/DIE \n\t\/\/ERROR String\n\t\/\/INFO (Maybe String)\n\t\/\/INVITE String String\n\t\/\/ISON [String]\n\t\tJOIN chs = [\"JOIN\",if (isEmpty chs) \"0\"\n\t\t\t(jon \", \" [jon \" \" [ch:maybeToList mk]\\\\(ch, mk)<-chs])]\n\t\/\/KICK String String (Maybe String)\n\t\/\/KILL String String\n\t\/\/LINKS (Maybe (Maybe String, String))\n\t\/\/LIST (Maybe ([String], Maybe String))\n\t\/\/LUSERS (Maybe (String, Maybe String))\n\t\/\/MODE String String (Maybe String) (Maybe String) (Maybe String)\n\t\/\/MOTD (Maybe String)\n\t\/\/NAMES [String]\n\t\tNICK n ms = [\"NICK\", n]\n\t\/\/NJOIN \n\t\/\/NOTICE String String\n\t\/\/OPER String String \n\t\/\/PART [String]\n\t\/\/PASS String\n\t\tPING a mb = [\"PING\",a:maybeToList mb]\n\t\tPONG a mb = [\"PONG\",a:maybeToList mb]\n\t\tPRIVMSG dest msg = [\"PRIVMSG\",jon \",\" dest,formatMSG msg]\n\t\tQUIT msg = [\"QUIT\":maybeToList msg]\n\t\/\/REHASH \n\t\/\/RESTART \n\t\/\/SERVER \n\t\/\/SERVICE String String String String\n\t\/\/SERVLIST (Maybe (String, Maybe String))\n\t\/\/SQUERY String String\n\t\/\/SQUIRT \n\t\/\/SQUIT String String\n\t\/\/STATS (Maybe (String, Maybe String))\n\t\/\/SUMMON String (Maybe (String, Maybe String))\n\t\/\/TIME (Maybe String)\n\t\/\/TOPIC String (Maybe String)\n\t\/\/TRACE (Maybe String)\n\t\tUSER login mode rn = [\"USER\", login, mode, \"*\", \":\"+++rn]\n\t\/\/USERHOST [String]\n\t\/\/USERS (Maybe String)\n\t\/\/VERSION (Maybe String)\n\t\/\/WALLOPS String\n\t\/\/WHO (Maybe String)\n\t\/\/WHOIS (Maybe String) [String]\n\t\/\/WHOWAS (Maybe String) [String]\n\t\t_ = [printToString r]\n\nformatMSG :: String -> String\nformatMSG s = if (indexOf \" \" s > 0 || indexOf \" \" s > 0) (\":\" +++ s) s\n\n\ninstance toString IRCReplies where toString r = printToString r\ninstance toString IRCErrors where toString r = printToString r\n\ninstance fromInt IRCReplies where\n\tfromInt r = case r of \n\t\t1 = RPL_WELCOME\n\t\t2 = RPL_YOURHOST\n\t\t3 = RPL_CREATED\n\t\t4 = RPL_MYINFO\n\t\t5 = RPL_BOUNCE\n\t\t200 = RPL_TRACELINK\n\t\t201 = RPL_TRACECONNECTING\n\t\t202 = RPL_TRACEHANDSHAKE\n\t\t203 = RPL_TRACEUNKNOWN\n\t\t204 = RPL_TRACEOPERATOR\n\t\t205 = RPL_TRACEUSER\n\t\t206 = RPL_TRACESERVER\n\t\t207 = RPL_TRACESERVICE\n\t\t208 = RPL_TRACENEWTYPE\n\t\t209 = RPL_TRACECLASS\n\t\t210 = RPL_TRACERECONNECT\n\t\t211 = RPL_STATSLINKINFO\n\t\t212 = RPL_STATSCOMMANDS\n\t\t219 = RPL_ENDOFSTATS\n\t\t221 = RPL_UMODEIS\n\t\t234 = RPL_SERVLIST\n\t\t235 = RPL_SERVLISTEND\n\t\t242 = RPL_STATSUPTIME\n\t\t243 = RPL_STATSOLINE\n\t\t251 = RPL_LUSERCLIENT\n\t\t252 = RPL_LUSEROP\n\t\t253 = RPL_LUSERUNKNOWN\n\t\t254 = RPL_LUSERCHANNELS\n\t\t255 = RPL_LUSERME\n\t\t256 = RPL_ADMINME\n\t\t257 = RPL_ADMINLOC1\n\t\t258 = RPL_ADMINLOC2\n\t\t259 = RPL_ADMINEMAIL\n\t\t261 = RPL_TRACELOG\n\t\t262 = RPL_TRACEEND\n\t\t263 = RPL_TRYAGAIN\n\t\t301 = RPL_AWAY\n\t\t302 = RPL_USERHOST\n\t\t303 = RPL_ISON\n\t\t304 = RPL_UNAWAY\n\t\t305 = RPL_NOWAWAY\n\t\t311 = RPL_WHOISUSER\n\t\t312 = RPL_WHOISSERVER\n\t\t313 = RPL_WHOISOPERATOR\n\t\t314 = RPL_WHOWASUSER\n\t\t315 = RPL_ENDOFWHO\n\t\t317 = RPL_WHOISIDLE\n\t\t318 = RPL_ENDOFWHOIS\n\t\t319 = RPL_WHOISCHANNELS\n\t\t321 = RPL_LISTSTART\n\t\t322 = RPL_LIST\n\t\t323 = RPL_LISTEND\n\t\t324 = RPL_CHANNELMODEIS\n\t\t325 = RPL_UNIQOPIS\n\t\t331 = RPL_NOTOPIC\n\t\t332 = RPL_TOPIC\n\t\t341 = RPL_INVITING\n\t\t342 = RPL_SUMMONING\n\t\t346 = RPL_INVITELIST\n\t\t347 = RPL_ENDOFINVITELIST\n\t\t348 = RPL_EXCEPTLIST\n\t\t349 = RPL_ENDOFEXCEPTLIST\n\t\t351 = RPL_VERSION\n\t\t352 = RPL_WHOREPLY\n\t\t353 = RPL_NAMREPLY\n\t\t364 = RPL_LINKS\n\t\t365 = RPL_ENDOFLINKS\n\t\t366 = RPL_ENDOFNAMES\n\t\t367 = RPL_BANLIST\n\t\t368 = RPL_ENDOFBANLIST\n\t\t369 = RPL_ENDOFWHOWAS\n\t\t371 = RPL_INFO\n\t\t372 = RPL_MOTD\n\t\t374 = RPL_ENDOFINFO\n\t\t375 = RPL_MOTDSTART\n\t\t376 = RPL_ENDOFMOTD\n\t\t381 = RPL_YOUREOPER\n\t\t382 = RPL_REHASHING\n\t\t383 = RPL_YOURESERVICE\n\t\t391 = RPL_TIME\n\t\t392 = RPL_USERSSTART\n\t\t393 = RPL_USERS\n\t\t394 = RPL_ENDOFUSERS\n\t\t395 = RPL_NOUSERS\n\t\t_ = undef\n\ninstance toInt IRCReplies where\n\ttoInt r = case r of \n\t\tRPL_WELCOME = 1\n\t\tRPL_YOURHOST = 2\n\t\tRPL_CREATED = 3\n\t\tRPL_MYINFO = 4\n\t\tRPL_BOUNCE = 5\n\t\tRPL_TRACELINK = 200\n\t\tRPL_TRACECONNECTING = 201\n\t\tRPL_TRACEHANDSHAKE = 202\n\t\tRPL_TRACEUNKNOWN = 203\n\t\tRPL_TRACEOPERATOR = 204\n\t\tRPL_TRACEUSER = 205\n\t\tRPL_TRACESERVER = 206\n\t\tRPL_TRACESERVICE = 207\n\t\tRPL_TRACENEWTYPE = 208\n\t\tRPL_TRACECLASS = 209\n\t\tRPL_TRACERECONNECT = 210\n\t\tRPL_STATSLINKINFO = 211\n\t\tRPL_STATSCOMMANDS = 212\n\t\tRPL_ENDOFSTATS = 219\n\t\tRPL_UMODEIS = 221\n\t\tRPL_SERVLIST = 234\n\t\tRPL_SERVLISTEND = 234\n\t\tRPL_STATSUPTIME = 242\n\t\tRPL_STATSOLINE = 243\n\t\tRPL_LUSERCLIENT = 251\n\t\tRPL_LUSEROP = 252\n\t\tRPL_LUSERUNKNOWN = 253\n\t\tRPL_LUSERCHANNELS = 254\n\t\tRPL_LUSERME = 255\n\t\tRPL_ADMINME = 256\n\t\tRPL_ADMINLOC1 = 257\n\t\tRPL_ADMINLOC2 = 258\n\t\tRPL_ADMINEMAIL = 259\n\t\tRPL_TRACELOG = 261\n\t\tRPL_TRACEEND = 262\n\t\tRPL_TRYAGAIN = 263\n\t\tRPL_AWAY = 301\n\t\tRPL_USERHOST = 302\n\t\tRPL_ISON = 303\n\t\tRPL_UNAWAY = 304\n\t\tRPL_NOWAWAY = 305\n\t\tRPL_WHOISUSER = 311\n\t\tRPL_WHOISSERVER = 312\n\t\tRPL_WHOISOPERATOR = 313\n\t\tRPL_WHOWASUSER = 314\n\t\tRPL_ENDOFWHO = 315\n\t\tRPL_WHOISIDLE = 317\n\t\tRPL_ENDOFWHOIS = 318\n\t\tRPL_WHOISCHANNELS = 319\n\t\tRPL_LISTSTART = 321\n\t\tRPL_LIST = 322\n\t\tRPL_LISTEND = 323\n\t\tRPL_CHANNELMODEIS = 324\n\t\tRPL_UNIQOPIS = 325\n\t\tRPL_NOTOPIC = 331\n\t\tRPL_TOPIC = 332\n\t\tRPL_INVITING = 341\n\t\tRPL_SUMMONING = 342\n\t\tRPL_INVITELIST = 346\n\t\tRPL_ENDOFINVITELIST = 347\n\t\tRPL_EXCEPTLIST = 348\n\t\tRPL_ENDOFEXCEPTLIST = 349\n\t\tRPL_VERSION = 351\n\t\tRPL_WHOREPLY = 352\n\t\tRPL_NAMREPLY = 353\n\t\tRPL_LINKS = 364\n\t\tRPL_ENDOFLINKS = 365\n\t\tRPL_ENDOFNAMES = 366\n\t\tRPL_BANLIST = 367\n\t\tRPL_ENDOFBANLIST = 367\n\t\tRPL_ENDOFWHOWAS = 369\n\t\tRPL_INFO = 371\n\t\tRPL_MOTD = 372\n\t\tRPL_ENDOFINFO = 374\n\t\tRPL_MOTDSTART = 375\n\t\tRPL_ENDOFMOTD = 376\n\t\tRPL_YOUREOPER = 381\n\t\tRPL_REHASHING = 382\n\t\tRPL_YOURESERVICE = 383\n\t\tRPL_TIME = 391\n\t\tRPL_USERSSTART = 392\n\t\tRPL_USERS = 393\n\t\tRPL_ENDOFUSERS = 394\n\t\tRPL_NOUSERS = 395\n\ninstance fromInt IRCErrors where\n\tfromInt r = case r of\n\t\t401 = ERR_NOSUCHNICK\n\t\t402 = ERR_NOSUCHSERVER\n\t\t403 = ERR_NOSUCHCHANNEL\n\t\t404 = ERR_CANNOTSENDTOCHAN\n\t\t405 = ERR_TOOMANYCHANNELS\n\t\t406 = ERR_WASNOSUCHNICK\n\t\t407 = ERR_TOOMANYTARGETS\n\t\t408 = ERR_NOSUCHSERVICE\n\t\t409 = ERR_NOORIGIN\n\t\t411 = ERR_NORECIPIENT\n\t\t412 = ERR_NOTEXTTOSEND\n\t\t413 = ERR_NOTOPLEVEL\n\t\t414 = ERR_WILDTOPLEVEL\n\t\t415 = ERR_BADMASK\n\t\t421 = ERR_UNKNOWNCOMMAND\n\t\t422 = ERR_NOMOTD\n\t\t423 = ERR_NOADMININFO\n\t\t424 = ERR_FILEERROR\n\t\t431 = ERR_NONICKNAMEGIVEN\n\t\t432 = ERR_ERRONEUSNICKNAME\n\t\t433 = ERR_NICKNAMEINUSE\n\t\t436 = ERR_NICKCOLLISION\n\t\t437 = ERR_UNAVAILRESOURCE\n\t\t441 = ERR_USERNOTINCHANNEL\n\t\t442 = ERR_NOTONCHANNEL\n\t\t443 = ERR_USERONCHANNEL\n\t\t444 = ERR_NOLOGIN\n\t\t445 = ERR_SUMMONDISABLED\n\t\t446 = ERR_USERSDISABLED\n\t\t451 = ERR_NOTREGISTERED\n\t\t461 = ERR_NEEDMOREPARAMS\n\t\t462 = ERR_ALREADYREGISTRED\n\t\t463 = ERR_NOPERMFORHOST\n\t\t464 = ERR_PASSWDMISMATCH\n\t\t465 = ERR_YOUREBANNEDCREEP\n\t\t466 = ERR_YOUWILLBEBANNED\n\t\t467 = ERR_KEYSET\n\t\t471 = ERR_CHANNELISFULL\n\t\t472 = ERR_UNKNOWNMODE\n\t\t473 = ERR_INVITEONLYCHAN\n\t\t474 = ERR_BANNEDFROMCHAN\n\t\t475 = ERR_BADCHANNELKEY\n\t\t476 = ERR_BADCHANMASK\n\t\t477 = ERR_NOCHANMODES\n\t\t478 = ERR_BANLISTFULL\n\t\t481 = ERR_NOPRIVILEGES\n\t\t482 = ERR_CHANOPRIVSNEEDED\n\t\t483 = ERR_CANTKILLSERVER\n\t\t484 = ERR_RESTRICTED\n\t\t485 = ERR_UNIQOPPRIVSNEEDED\n\t\t491 = ERR_NOOPERHOST\n\t\t501 = ERR_UMODEUNKNOWNFLAG\n\t\t502 = ERR_USERSDONTMATCH\n\ninstance toInt IRCErrors where\n\ttoInt r = case r of\n\t\tERR_NOSUCHNICK = 401\n\t\tERR_NOSUCHSERVER = 402\n\t\tERR_NOSUCHCHANNEL = 403\n\t\tERR_CANNOTSENDTOCHAN = 404\n\t\tERR_TOOMANYCHANNELS = 405\n\t\tERR_WASNOSUCHNICK = 406\n\t\tERR_TOOMANYTARGETS = 407\n\t\tERR_NOSUCHSERVICE = 408\n\t\tERR_NOORIGIN = 409\n\t\tERR_NORECIPIENT = 411\n\t\tERR_NOTEXTTOSEND = 412\n\t\tERR_NOTOPLEVEL = 413\n\t\tERR_WILDTOPLEVEL = 414\n\t\tERR_BADMASK = 415\n\t\tERR_UNKNOWNCOMMAND = 421\n\t\tERR_NOMOTD = 422\n\t\tERR_NOADMININFO = 423\n\t\tERR_FILEERROR = 424\n\t\tERR_NONICKNAMEGIVEN = 431\n\t\tERR_ERRONEUSNICKNAME = 432\n\t\tERR_NICKNAMEINUSE = 433\n\t\tERR_NICKCOLLISION = 436\n\t\tERR_UNAVAILRESOURCE = 437\n\t\tERR_USERNOTINCHANNEL = 441\n\t\tERR_NOTONCHANNEL = 442\n\t\tERR_USERONCHANNEL = 443\n\t\tERR_NOLOGIN = 444\n\t\tERR_SUMMONDISABLED = 445\n\t\tERR_USERSDISABLED = 446\n\t\tERR_NOTREGISTERED = 451\n\t\tERR_NEEDMOREPARAMS = 461\n\t\tERR_ALREADYREGISTRED = 462\n\t\tERR_NOPERMFORHOST = 463\n\t\tERR_PASSWDMISMATCH = 464\n\t\tERR_YOUREBANNEDCREEP = 465\n\t\tERR_YOUWILLBEBANNED = 466\n\t\tERR_KEYSET = 467\n\t\tERR_CHANNELISFULL = 471\n\t\tERR_UNKNOWNMODE = 472\n\t\tERR_INVITEONLYCHAN = 473\n\t\tERR_BANNEDFROMCHAN = 474\n\t\tERR_BADCHANNELKEY = 475\n\t\tERR_BADCHANMASK = 476\n\t\tERR_NOCHANMODES = 477\n\t\tERR_BANLISTFULL = 478\n\t\tERR_NOPRIVILEGES = 481\n\t\tERR_CHANOPRIVSNEEDED = 482\n\t\tERR_CANTKILLSERVER = 483\n\t\tERR_RESTRICTED = 484\n\t\tERR_UNIQOPPRIVSNEEDED = 485\n\t\tERR_NOOPERHOST = 491\n\t\tERR_UMODEUNKNOWNFLAG = 501\n\t\tERR_USERSDONTMATCH = 502\n","old_contents":"implementation module IRC\n\nimport StdGeneric\nimport StdList\nimport GenPrint\nimport GenBimap\nimport StdOverloaded\nimport Data.Maybe\nimport Data.Either\nimport StdFunc\nimport StdString\nimport StdChar\nimport StdBool\nimport _SystemArray\n\nimport Text.Parsers.Simple.Core\nimport Text.Parsers.Simple.Chars\nimport Data.Tuple\nimport Control.Monad\nimport Control.Applicative\nfrom Data.Functor import <$>\n\nfrom Data.Func import $\nfrom Text import class Text(ltrim,indexOf,concat), instance Text String\nimport qualified Text\nfrom StdMisc import undef\nimport StdDebug\n\njon :== 'Text'.join\n\nderive gPrint IRCCommand, IRCReplies, IRCErrors, (,), Maybe, (), Either, IRCMessage, IRCUser, IRCNumReply\n\nStart = jon \"\\n\" $ map printToString\n\t[ parseIRCMessage \":clooglebot!~cloogle@dhcp-077-249-221-037.chello.nl QUIT\\r\\n\"\n\t, parseIRCMessage \":clooglebot!~cloogle QUIT\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 QUIT\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY test\\r\\n\"\n\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY :test with spaces\\r\\n\"\n\t, parseIRCMessage \":cherryh.freenode.net NOTICE * :*** Found your hostname\\r\\n\"\n\t, parseIRCMessage \":cherryh.freenode.net QUIT :hoi hoi\\r\\n\"\n\t]\n\n(<+) infixr 5 :: a b -> String | toString a & toString b\n(<+) a b = toString a +++ toString b\n\nparseIRCMessage :: String -> Either [Error] IRCMessage\nparseIRCMessage s = case runParser parsePrefix (fromString s) of\n\t([(prefix, rest):_], _)\n\t\t= case parse parseReply rest of\n\t\t\tLeft e = case parseCmd rest of\n\t\t\t\tLeft e2 = Left $ e2 ++ e\n\t\t\t\tRight cmd = Right {IRCMessage | irc_prefix=prefix, irc_command=Right cmd}\n\t\t\tRight repl = Right {IRCMessage | irc_prefix=prefix, irc_command=Left repl}\n\t(_, es) = Left [\"couldn't parse prefix\":es]\n\nparsePrefix :: Parser Char (Maybe (Either IRCUser String))\nparsePrefix = optional (pToken ':' >>| parseEither parseUser parseHost) <* pToken ' '\n\ngeneric gIRCParse a :: Parser String a\ngIRCParse{|String|} = pSatisfy (const True)\ngIRCParse{|Int|} = toInt <$> pSatisfy (const True)\ngIRCParse{|EITHER|} p b = LEFT <$> p <|> RIGHT <$> b\ngIRCParse{|PAIR|} p b = liftM2 PAIR p b\ngIRCParse{|UNIT|} = pFail\ngIRCParse{|OBJECT|} p = OBJECT <$> p\ngIRCParse{|CONS of d|} p = CONS <$> (pToken d.gcd_name >>| p)\ngIRCParse{|Maybe|} p = optional p\ngIRCParse{|(,)|} p s = liftM2 tuple p s\ngIRCParse{|[]|} p = pMany p\ngIRCParse{|(->)|} p b = undef\n\nderive gIRCParse IRCCommand\n\nparseCmd :: [Char] -> Either [Error] IRCCommand\nparseCmd cs\n= parse gIRCParse{|*|} $ argfun $ 'Text'.split \" \" $ toString cs\n\/\/= parse cmdParser $ argfun $ 'Text'.split \" \" $ toString cs\n\twhere\n\t\targfun :: [String] -> [String]\n\t\targfun [] = []\n\t\targfun [x:xs]\n\t\t# x = 'Text'.trim x\n\t\t| x.[0] == ':' = [jon \" \" $ [x:map 'Text'.rtrim xs]]\n\t\t| otherwise = [x:argfun xs]\n\n\t\tp = pSatisfy (const True)\n\t\tlst = fmap $ 'Text'.split \",\"\n\t\topt = optional p\n\t\tpInt = toInt <$> p\n\n\t\tnn p f = pToken p >>| f\n\n\t\tcmdParser :: Parser String IRCCommand\n\t\tcmdParser =\n\t\t\t (nn \"ADMIN\" $ fmap ADMIN opt)\n\t\t\t<|> (nn \"AWAY\" $ fmap AWAY p)\n\t\t\t<|> (nn \"CONNECT\" $ liftM2 CONNECT p (optional $ liftM2 tuple pInt opt))\n\t\t\t<|> (nn \"DIE\" $ pure DIE)\n\t\t\t<|> (nn \"ERROR\" $ fmap ERROR p)\n\t\t\t<|> (nn \"INFO\" $ fmap INFO opt)\n\t\t\t<|> (nn \"INVITE\" $ liftM2 INVITE p p)\n\t\t\t<|> (nn \"ISON\" $ fmap ISON $ pMany p)\n\/\/\t\t\t<|> (nn \"JOIN\" $ fmap JOIN $ lst p >>= \\ch->lst p >>= \\ks->pure (zip2 ch (ks ++ repeat Nothing)))\n\t\t\t<|> (nn \"KICK\" $ liftM3 KICK p p opt)\n\t\t\t<|> (nn \"KILL\" $ liftM2 KILL p p)\n\t\t\t<|> (nn \"LINKS\" $ fmap LINKS $ optional $ liftM2 tuple opt p)\n\t\t\t<|> (nn \"LIST\" $ fmap LIST $ optional $ liftM2 tuple ('Text'.split \",\" <$> p) opt)\n\t\t\t<|> (nn \"LUSERS\" $ fmap LUSERS $ optional $ liftM2 tuple p opt)\n\t\t\t<|> (nn \"MODE\" $ liftM5 MODE p p opt opt opt)\n\t\t\t<|> (nn \"MOTD\" $ fmap MOTD $ opt)\n\t\t\t<|> (nn \"NAMES\" $ fmap NAMES $ lst p)\n\t\t\t<|> (nn \"NICK\" $ fmap NAMES $ lst p)\n\t\t\t\/\/\"NICK\" = String (Maybe String)\n\t\t\t\/\/\"NJOIN\" = command0 NJOIN args\n\t\t\t\/\/\"NOTICE\" = String String\n\t\t\t\/\/\"OPER\" = String String \n\t\t\t\/\/\"PART\" = [String]\n\t\t\t\/\/\"PASS\" = String\n\t\t\t\/\/\"PING\" = String (Maybe String)\n\t\t\t\/\/\"PONG\" = String (Maybe String)\n\t\t\t\/\/\"PRIVMSG\" = [String] String\n\/\/\t\t\t\"QUIT\" = case args of\n\/\/\t\t\t\t[_,_:_] = Left $ \"QUIT has too many arguments\"\n\/\/\t\t\t\tx = Right $ QUIT $ listToMaybe x\n\/\/\t\t\t\"REHASH\" = command0 REHASH args\n\/\/\t\t\t\"RESTART\" = command0 REHASH args\n\/\/\t\t\t\"SERVER\" = command0 REHASH args\n\t\t\t\/\/\"SERVICE\" = String String String String\n\t\t\t\/\/\"SERVLIST\" = (Maybe (String, Maybe String))\n\t\t\t\/\/\"SQUERY\" = String String\n\/\/\t\t\t\"SQUIRT\" = command0 REHASH args\n\t\t\t\/\/\"SQUIT\" = String String\n\t\t\t\/\/\"STATS\" = (Maybe (String, Maybe String))\n\t\t\t\/\/\"SUMMON\" = String (Maybe (String, Maybe String))\n\t\t\t\/\/\"TIME\" = (Maybe String)\n\t\t\t\/\/\"TOPIC\" = String (Maybe String)\n\t\t\t\/\/\"TRACE\" = (Maybe String)\n\t\t\t\/\/\"USER\" = String String String\n\t\t\t\/\/\"USERHOST\" = [String]\n\t\t\t\/\/\"USERS\" = (Maybe String)\n\t\t\t\/\/\"VERSION\" = (Maybe String)\n\t\t\t\/\/\"WALLOPS\" = String\n\t\t\t\/\/\"WHO\" = (Maybe String)\n\t\t\t\/\/\"WHOIS\" = (Maybe String) [String]\n\t\t\t\/\/\"WHOWAS\" = (Maybe String) [String]\n\nparseReply :: Parser Char IRCNumReply\nparseReply = (toString <$> pSome pDigit)\n\t>>= \\rep->pMiddle\n\t>>= \\recipient->spaceParser >>| (toString <$> pSome (pNoneOf illegal))\n\t>>= \\msg->pure {IRCNumReply|irc_reply=fs rep,irc_recipient=recipient,irc_message=msg}\n\twhere\n\t\tfs :: String -> IRCReplies\n\t\tfs s = fromInt $ toInt s\n\nspaceParser :: Parser Char [Char]\nspaceParser = pMany $ pToken ' '\n\nparseServer :: Parser Char String\nparseServer = pFail\n\nparseEither :: (Parser a b) (Parser a c) -> Parser a (Either b c)\nparseEither p q = Left <$> p <|> Right <$> q\n\nparseUser :: Parser Char IRCUser\nparseUser = parseNick\n\t\t>>= \\nick->optional (pToken '!' >>| parseUsr)\n\t\t>>= \\muser->optional (pToken '@' >>| parseHost)\n\t\t>>= \\mhost->pure {IRCUser | irc_nick=nick, irc_user=muser, irc_host=mhost}\n\nparseUsr :: Parser Char String\nparseUsr = toString <$> pSome (pNoneOf [' ', '@':illegal])\n\nparseNick :: Parser Char String\nparseNick = pAlpha >>= \\c->pMany (pAlpha <|> pDigit <|> pSpecial)\n\t>>= \\cs->pure (toString [c:cs])\n\npSpecial :: Parser Char Char\npSpecial = pOneOf ['-', '[', ']', '\\\\', '\\`', '^', '{', '}']\n\nparseHost :: Parser Char String\nparseHost = jon \".\" <$> pSepBy parseName (pToken '.')\n\twhere\n\t\tparseName :: Parser Char String\n\t\tparseName = toString <$> pSome (pAlpha <|> pDigit <|> pOneOf ['-'])\n\ninstance toString IRCNumReply where\n\ttoString m = toInt m.irc_reply <+ \" \" <+ m.irc_recipient <+ \" \" <+ formatMSG m.irc_message\ninstance toString IRCMessage where\n\ttoString m = maybe \"\" (\\s->either ((<+) \":\") id s <+ \" \") m.irc_prefix\n\t\t<+ either toString toString m.irc_command\n\ninstance toString IRCUser where\n\ttoString m = m.irc_nick <+ maybe \"\" ((<+) \"!\") m.irc_user\n\t\t<+ maybe \"\" ((<+) \"@\") m.irc_host\n\ncons :: a [a] -> [a]\ncons a as = [a:as]\n\npMiddle :: Parser Char String\npMiddle = fmap toString $\n\tspaceParser >>| liftM2 cons (pNotSatisfy ((==)':')) (pMany $ pNoneOf [' ':illegal])\n\npTrailing :: Parser Char String\npTrailing = fmap toString $ \n\tspaceParser >>| pToken ':' >>| pMany (pNoneOf illegal)\n\npParam :: Parser Char String\npParam = pMiddle <|> pTrailing\n\npNoneOf :: [a] -> Parser a a | Eq a\npNoneOf l = pSatisfy (not o flip isMember l)\n\npNotSatisfy :: (a -> Bool) -> Parser a a | Eq a\npNotSatisfy f = pSatisfy (not o f)\n\npInt :: Parser Char Int\npInt = toInt o toString <$> (spaceParser >>| pSome pDigit)\n\nillegal :: [Char]\nillegal = ['\\x00','\\r','\\n']\n\ninstance toString IRCCommand where\n\ttoString r = jon \" \" (print r) +++ \"\\r\\n\"\n\nprint :: IRCCommand -> [String]\nprint r = case r of\n\t\tADMIN mm = [\"ADMIN\":maybeToList mm]\n\t\tAWAY m = [\"AWAY\",m]\n\t\/\/CONNECT String (Maybe (Int, Maybe String))\n\t\/\/DIE \n\t\/\/ERROR String\n\t\/\/INFO (Maybe String)\n\t\/\/INVITE String String\n\t\/\/ISON [String]\n\t\tJOIN chs = [\"JOIN\",if (isEmpty chs) \"0\"\n\t\t\t(jon \", \" [jon \" \" [ch:maybeToList mk]\\\\(ch, mk)<-chs])]\n\t\/\/KICK String String (Maybe String)\n\t\/\/KILL String String\n\t\/\/LINKS (Maybe (Maybe String, String))\n\t\/\/LIST (Maybe ([String], Maybe String))\n\t\/\/LUSERS (Maybe (String, Maybe String))\n\t\/\/MODE String String (Maybe String) (Maybe String) (Maybe String)\n\t\/\/MOTD (Maybe String)\n\t\/\/NAMES [String]\n\t\tNICK n ms = [\"NICK\", n]\n\t\/\/NJOIN \n\t\/\/NOTICE String String\n\t\/\/OPER String String \n\t\/\/PART [String]\n\t\/\/PASS String\n\t\tPING a mb = [\"PING\",a:maybeToList mb]\n\t\tPONG a mb = [\"PONG\",a:maybeToList mb]\n\t\tPRIVMSG dest msg = [\"PRIVMSG\",jon \",\" dest,formatMSG msg]\n\t\tQUIT msg = [\"QUIT\":maybeToList msg]\n\t\/\/REHASH \n\t\/\/RESTART \n\t\/\/SERVER \n\t\/\/SERVICE String String String String\n\t\/\/SERVLIST (Maybe (String, Maybe String))\n\t\/\/SQUERY String String\n\t\/\/SQUIRT \n\t\/\/SQUIT String String\n\t\/\/STATS (Maybe (String, Maybe String))\n\t\/\/SUMMON String (Maybe (String, Maybe String))\n\t\/\/TIME (Maybe String)\n\t\/\/TOPIC String (Maybe String)\n\t\/\/TRACE (Maybe String)\n\t\tUSER login mode rn = [\"USER\", login, mode, \"*\", \":\"+++rn]\n\t\/\/USERHOST [String]\n\t\/\/USERS (Maybe String)\n\t\/\/VERSION (Maybe String)\n\t\/\/WALLOPS String\n\t\/\/WHO (Maybe String)\n\t\/\/WHOIS (Maybe String) [String]\n\t\/\/WHOWAS (Maybe String) [String]\n\t\t_ = [printToString r]\n\nformatMSG :: String -> String\nformatMSG s = if (indexOf \" \" s > 0 || indexOf \" \" s > 0) (\":\" +++ s) s\n\n\ninstance toString IRCReplies where toString r = printToString r\ninstance toString IRCErrors where toString r = printToString r\n\ninstance fromInt IRCReplies where\n\tfromInt r = case r of \n\t\t1 = RPL_WELCOME\n\t\t2 = RPL_YOURHOST\n\t\t3 = RPL_CREATED\n\t\t4 = RPL_MYINFO\n\t\t5 = RPL_BOUNCE\n\t\t200 = RPL_TRACELINK\n\t\t201 = RPL_TRACECONNECTING\n\t\t202 = RPL_TRACEHANDSHAKE\n\t\t203 = RPL_TRACEUNKNOWN\n\t\t204 = RPL_TRACEOPERATOR\n\t\t205 = RPL_TRACEUSER\n\t\t206 = RPL_TRACESERVER\n\t\t207 = RPL_TRACESERVICE\n\t\t208 = RPL_TRACENEWTYPE\n\t\t209 = RPL_TRACECLASS\n\t\t210 = RPL_TRACERECONNECT\n\t\t211 = RPL_STATSLINKINFO\n\t\t212 = RPL_STATSCOMMANDS\n\t\t219 = RPL_ENDOFSTATS\n\t\t221 = RPL_UMODEIS\n\t\t234 = RPL_SERVLIST\n\t\t235 = RPL_SERVLISTEND\n\t\t242 = RPL_STATSUPTIME\n\t\t243 = RPL_STATSOLINE\n\t\t251 = RPL_LUSERCLIENT\n\t\t252 = RPL_LUSEROP\n\t\t253 = RPL_LUSERUNKNOWN\n\t\t254 = RPL_LUSERCHANNELS\n\t\t255 = RPL_LUSERME\n\t\t256 = RPL_ADMINME\n\t\t257 = RPL_ADMINLOC1\n\t\t258 = RPL_ADMINLOC2\n\t\t259 = RPL_ADMINEMAIL\n\t\t261 = RPL_TRACELOG\n\t\t262 = RPL_TRACEEND\n\t\t263 = RPL_TRYAGAIN\n\t\t301 = RPL_AWAY\n\t\t302 = RPL_USERHOST\n\t\t303 = RPL_ISON\n\t\t304 = RPL_UNAWAY\n\t\t305 = RPL_NOWAWAY\n\t\t311 = RPL_WHOISUSER\n\t\t312 = RPL_WHOISSERVER\n\t\t313 = RPL_WHOISOPERATOR\n\t\t314 = RPL_WHOWASUSER\n\t\t315 = RPL_ENDOFWHO\n\t\t317 = RPL_WHOISIDLE\n\t\t318 = RPL_ENDOFWHOIS\n\t\t319 = RPL_WHOISCHANNELS\n\t\t321 = RPL_LISTSTART\n\t\t322 = RPL_LIST\n\t\t323 = RPL_LISTEND\n\t\t324 = RPL_CHANNELMODEIS\n\t\t325 = RPL_UNIQOPIS\n\t\t331 = RPL_NOTOPIC\n\t\t332 = RPL_TOPIC\n\t\t341 = RPL_INVITING\n\t\t342 = RPL_SUMMONING\n\t\t346 = RPL_INVITELIST\n\t\t347 = RPL_ENDOFINVITELIST\n\t\t348 = RPL_EXCEPTLIST\n\t\t349 = RPL_ENDOFEXCEPTLIST\n\t\t351 = RPL_VERSION\n\t\t352 = RPL_WHOREPLY\n\t\t353 = RPL_NAMREPLY\n\t\t364 = RPL_LINKS\n\t\t365 = RPL_ENDOFLINKS\n\t\t366 = RPL_ENDOFNAMES\n\t\t367 = RPL_BANLIST\n\t\t368 = RPL_ENDOFBANLIST\n\t\t369 = RPL_ENDOFWHOWAS\n\t\t371 = RPL_INFO\n\t\t372 = RPL_MOTD\n\t\t374 = RPL_ENDOFINFO\n\t\t375 = RPL_MOTDSTART\n\t\t376 = RPL_ENDOFMOTD\n\t\t381 = RPL_YOUREOPER\n\t\t382 = RPL_REHASHING\n\t\t383 = RPL_YOURESERVICE\n\t\t391 = RPL_TIME\n\t\t392 = RPL_USERSSTART\n\t\t393 = RPL_USERS\n\t\t394 = RPL_ENDOFUSERS\n\t\t395 = RPL_NOUSERS\n\t\t_ = undef\n\ninstance toInt IRCReplies where\n\ttoInt r = case r of \n\t\tRPL_WELCOME = 1\n\t\tRPL_YOURHOST = 2\n\t\tRPL_CREATED = 3\n\t\tRPL_MYINFO = 4\n\t\tRPL_BOUNCE = 5\n\t\tRPL_TRACELINK = 200\n\t\tRPL_TRACECONNECTING = 201\n\t\tRPL_TRACEHANDSHAKE = 202\n\t\tRPL_TRACEUNKNOWN = 203\n\t\tRPL_TRACEOPERATOR = 204\n\t\tRPL_TRACEUSER = 205\n\t\tRPL_TRACESERVER = 206\n\t\tRPL_TRACESERVICE = 207\n\t\tRPL_TRACENEWTYPE = 208\n\t\tRPL_TRACECLASS = 209\n\t\tRPL_TRACERECONNECT = 210\n\t\tRPL_STATSLINKINFO = 211\n\t\tRPL_STATSCOMMANDS = 212\n\t\tRPL_ENDOFSTATS = 219\n\t\tRPL_UMODEIS = 221\n\t\tRPL_SERVLIST = 234\n\t\tRPL_SERVLISTEND = 234\n\t\tRPL_STATSUPTIME = 242\n\t\tRPL_STATSOLINE = 243\n\t\tRPL_LUSERCLIENT = 251\n\t\tRPL_LUSEROP = 252\n\t\tRPL_LUSERUNKNOWN = 253\n\t\tRPL_LUSERCHANNELS = 254\n\t\tRPL_LUSERME = 255\n\t\tRPL_ADMINME = 256\n\t\tRPL_ADMINLOC1 = 257\n\t\tRPL_ADMINLOC2 = 258\n\t\tRPL_ADMINEMAIL = 259\n\t\tRPL_TRACELOG = 261\n\t\tRPL_TRACEEND = 262\n\t\tRPL_TRYAGAIN = 263\n\t\tRPL_AWAY = 301\n\t\tRPL_USERHOST = 302\n\t\tRPL_ISON = 303\n\t\tRPL_UNAWAY = 304\n\t\tRPL_NOWAWAY = 305\n\t\tRPL_WHOISUSER = 311\n\t\tRPL_WHOISSERVER = 312\n\t\tRPL_WHOISOPERATOR = 313\n\t\tRPL_WHOWASUSER = 314\n\t\tRPL_ENDOFWHO = 315\n\t\tRPL_WHOISIDLE = 317\n\t\tRPL_ENDOFWHOIS = 318\n\t\tRPL_WHOISCHANNELS = 319\n\t\tRPL_LISTSTART = 321\n\t\tRPL_LIST = 322\n\t\tRPL_LISTEND = 323\n\t\tRPL_CHANNELMODEIS = 324\n\t\tRPL_UNIQOPIS = 325\n\t\tRPL_NOTOPIC = 331\n\t\tRPL_TOPIC = 332\n\t\tRPL_INVITING = 341\n\t\tRPL_SUMMONING = 342\n\t\tRPL_INVITELIST = 346\n\t\tRPL_ENDOFINVITELIST = 347\n\t\tRPL_EXCEPTLIST = 348\n\t\tRPL_ENDOFEXCEPTLIST = 349\n\t\tRPL_VERSION = 351\n\t\tRPL_WHOREPLY = 352\n\t\tRPL_NAMREPLY = 353\n\t\tRPL_LINKS = 364\n\t\tRPL_ENDOFLINKS = 365\n\t\tRPL_ENDOFNAMES = 366\n\t\tRPL_BANLIST = 367\n\t\tRPL_ENDOFBANLIST = 367\n\t\tRPL_ENDOFWHOWAS = 369\n\t\tRPL_INFO = 371\n\t\tRPL_MOTD = 372\n\t\tRPL_ENDOFINFO = 374\n\t\tRPL_MOTDSTART = 375\n\t\tRPL_ENDOFMOTD = 376\n\t\tRPL_YOUREOPER = 381\n\t\tRPL_REHASHING = 382\n\t\tRPL_YOURESERVICE = 383\n\t\tRPL_TIME = 391\n\t\tRPL_USERSSTART = 392\n\t\tRPL_USERS = 393\n\t\tRPL_ENDOFUSERS = 394\n\t\tRPL_NOUSERS = 395\n\ninstance fromInt IRCErrors where\n\tfromInt r = case r of\n\t\t401 = ERR_NOSUCHNICK\n\t\t402 = ERR_NOSUCHSERVER\n\t\t403 = ERR_NOSUCHCHANNEL\n\t\t404 = ERR_CANNOTSENDTOCHAN\n\t\t405 = ERR_TOOMANYCHANNELS\n\t\t406 = ERR_WASNOSUCHNICK\n\t\t407 = ERR_TOOMANYTARGETS\n\t\t408 = ERR_NOSUCHSERVICE\n\t\t409 = ERR_NOORIGIN\n\t\t411 = ERR_NORECIPIENT\n\t\t412 = ERR_NOTEXTTOSEND\n\t\t413 = ERR_NOTOPLEVEL\n\t\t414 = ERR_WILDTOPLEVEL\n\t\t415 = ERR_BADMASK\n\t\t421 = ERR_UNKNOWNCOMMAND\n\t\t422 = ERR_NOMOTD\n\t\t423 = ERR_NOADMININFO\n\t\t424 = ERR_FILEERROR\n\t\t431 = ERR_NONICKNAMEGIVEN\n\t\t432 = ERR_ERRONEUSNICKNAME\n\t\t433 = ERR_NICKNAMEINUSE\n\t\t436 = ERR_NICKCOLLISION\n\t\t437 = ERR_UNAVAILRESOURCE\n\t\t441 = ERR_USERNOTINCHANNEL\n\t\t442 = ERR_NOTONCHANNEL\n\t\t443 = ERR_USERONCHANNEL\n\t\t444 = ERR_NOLOGIN\n\t\t445 = ERR_SUMMONDISABLED\n\t\t446 = ERR_USERSDISABLED\n\t\t451 = ERR_NOTREGISTERED\n\t\t461 = ERR_NEEDMOREPARAMS\n\t\t462 = ERR_ALREADYREGISTRED\n\t\t463 = ERR_NOPERMFORHOST\n\t\t464 = ERR_PASSWDMISMATCH\n\t\t465 = ERR_YOUREBANNEDCREEP\n\t\t466 = ERR_YOUWILLBEBANNED\n\t\t467 = ERR_KEYSET\n\t\t471 = ERR_CHANNELISFULL\n\t\t472 = ERR_UNKNOWNMODE\n\t\t473 = ERR_INVITEONLYCHAN\n\t\t474 = ERR_BANNEDFROMCHAN\n\t\t475 = ERR_BADCHANNELKEY\n\t\t476 = ERR_BADCHANMASK\n\t\t477 = ERR_NOCHANMODES\n\t\t478 = ERR_BANLISTFULL\n\t\t481 = ERR_NOPRIVILEGES\n\t\t482 = ERR_CHANOPRIVSNEEDED\n\t\t483 = ERR_CANTKILLSERVER\n\t\t484 = ERR_RESTRICTED\n\t\t485 = ERR_UNIQOPPRIVSNEEDED\n\t\t491 = ERR_NOOPERHOST\n\t\t501 = ERR_UMODEUNKNOWNFLAG\n\t\t502 = ERR_USERSDONTMATCH\n\ninstance toInt IRCErrors where\n\ttoInt r = case r of\n\t\tERR_NOSUCHNICK = 401\n\t\tERR_NOSUCHSERVER = 402\n\t\tERR_NOSUCHCHANNEL = 403\n\t\tERR_CANNOTSENDTOCHAN = 404\n\t\tERR_TOOMANYCHANNELS = 405\n\t\tERR_WASNOSUCHNICK = 406\n\t\tERR_TOOMANYTARGETS = 407\n\t\tERR_NOSUCHSERVICE = 408\n\t\tERR_NOORIGIN = 409\n\t\tERR_NORECIPIENT = 411\n\t\tERR_NOTEXTTOSEND = 412\n\t\tERR_NOTOPLEVEL = 413\n\t\tERR_WILDTOPLEVEL = 414\n\t\tERR_BADMASK = 415\n\t\tERR_UNKNOWNCOMMAND = 421\n\t\tERR_NOMOTD = 422\n\t\tERR_NOADMININFO = 423\n\t\tERR_FILEERROR = 424\n\t\tERR_NONICKNAMEGIVEN = 431\n\t\tERR_ERRONEUSNICKNAME = 432\n\t\tERR_NICKNAMEINUSE = 433\n\t\tERR_NICKCOLLISION = 436\n\t\tERR_UNAVAILRESOURCE = 437\n\t\tERR_USERNOTINCHANNEL = 441\n\t\tERR_NOTONCHANNEL = 442\n\t\tERR_USERONCHANNEL = 443\n\t\tERR_NOLOGIN = 444\n\t\tERR_SUMMONDISABLED = 445\n\t\tERR_USERSDISABLED = 446\n\t\tERR_NOTREGISTERED = 451\n\t\tERR_NEEDMOREPARAMS = 461\n\t\tERR_ALREADYREGISTRED = 462\n\t\tERR_NOPERMFORHOST = 463\n\t\tERR_PASSWDMISMATCH = 464\n\t\tERR_YOUREBANNEDCREEP = 465\n\t\tERR_YOUWILLBEBANNED = 466\n\t\tERR_KEYSET = 467\n\t\tERR_CHANNELISFULL = 471\n\t\tERR_UNKNOWNMODE = 472\n\t\tERR_INVITEONLYCHAN = 473\n\t\tERR_BANNEDFROMCHAN = 474\n\t\tERR_BADCHANNELKEY = 475\n\t\tERR_BADCHANMASK = 476\n\t\tERR_NOCHANMODES = 477\n\t\tERR_BANLISTFULL = 478\n\t\tERR_NOPRIVILEGES = 481\n\t\tERR_CHANOPRIVSNEEDED = 482\n\t\tERR_CANTKILLSERVER = 483\n\t\tERR_RESTRICTED = 484\n\t\tERR_UNIQOPPRIVSNEEDED = 485\n\t\tERR_NOOPERHOST = 491\n\t\tERR_UMODEUNKNOWNFLAG = 501\n\t\tERR_USERSDONTMATCH = 502\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"e6278aa2a6f96e3ea26a378c241b40dbcba54838","subject":"Tweak VMS help file building.","message":"Tweak VMS help file building.\n\nPrimarily this is handling cases where top-level files moved into\nthe docs\/ directory. I also corrected a typo and removed the\nclaim that libssh2 is public domain.\n","repos":"libssh2\/libssh2,libssh2\/libssh2,libssh2\/libssh2,libssh2\/libssh2","old_file":"vms\/libssh2_make_help.dcl","new_file":"vms\/libssh2_make_help.dcl","new_contents":"$!\n$!\n$!\n$ olddir = f$environment( \"default\" )\n$ on control_y then goto End\n$ on error then goto End\n$!\n$ gosub Init\n$!\n$ man2help sys$input: libssh2.hlp -b 1\n\nLIBSSH2\n\nOpenVMS port of the libssh2 library, which provides an\nAPI to implement client SSH communication.\n\nLicense information is available at the Copying subtopic.\n\n$!\n$ open\/append mh libssh2.hlp\n$ write mh helpversion\n$ close mh\n$!\n$ man2help -a [-]README.; libssh2.hlp -b 2\n$ man2help -a [-]COPYING.; libssh2.hlp -b 2\n$ man2help -a [-]NEWS.; libssh2.hlp -b 2\n$ man2help -a [-]RELEASE-NOTES.; libssh2.hlp -b 2\n$ man2help -a [-.docs]AUTHORS.; libssh2.hlp -b 2\n$ man2help -a [-.docs]BINDINGS.; libssh2.hlp -b 2\n$ man2help -a [-.docs]HACKING.; libssh2.hlp -b 2\n$ if f$search(\"[]HACKING_CRYPTO.\") .nes. \"\" then delete []HACKING_CRYPTO.;*\n$ copy [-.docs]HACKING.CRYPTO; []HACKING_CRYPTO.\n$ man2help -a []HACKING_CRYPTO.; libssh2.hlp -b 2\n$ man2help -a [-.docs]TODO.; libssh2.hlp -b 2\n$!\n$ man2help -a sys$input: libssh2.hlp -b 2\n\nAPI_Reference\n\nReference of all implemented API calls in\nlibssh2.\n\n$!\n$ man2help -a [-.docs]*.3 libssh2.hlp -b 3 -p\n$!\n$ library\/help\/create libssh2.hlb libssh2.hlp\n$!\n$End:\n$ set default 'olddir'\n$exit\n$!\n$!-------------------------------------------------------\n$!\n$Init:\n$!\n$ thisdir = f$environment( \"procedure\" )\n$ thisdir = f$parse(thisdir,,,\"device\") + f$parse(thisdir,,,\"directory\")\n$ set default 'thisdir'\n$! \n$ say = \"write sys$output\"\n$!\n$ pipe search [-.include]*.h libssh2_version_major\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job majorv &l )\n$ pipe search [-.include]*.h libssh2_version_minor\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job minorv &l )\n$ pipe search [-.include]*.h libssh2_version_patch\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job patchv &l )\n$!\n$ majorv = f$trnlnm(\"majorv\")\n$ minorv = f$integer(f$trnlnm(\"minorv\")) \n$ patchv = f$integer( f$trnlnm(\"patchv\"))\n$!\n$ helpversion = \"This help library is based on build version ''majorv'.''minorv'.''patchv' of libssh2.\"\n$!\n$ deassign\/job majorv\n$ deassign\/job minorv\n$ deassign\/job patchv\n$!\n$ if f$search( \"man2help.exe\" ) .eqs. \"\"\n$ then\n$ cc man2help\n$ link man2help\n$ endif\n$! \n$ man2help := $'thisdir'man2help.exe \n$!\n$ if f$search(\"libssh2.hlp\") .nes. \"\" \n$ then \n$ delete libssh2.hlp;*\n$ endif\n$ if f$search(\"libssh2.hlb\") .nes. \"\" \n$ then \n$ delete libssh2.hlb;*\n$ endif\n$return\n","old_contents":"$!\n$!\n$!\n$ olddir = f$environment( \"default\" )\n$ on control_y then goto End\n$ on error then goto End\n$!\n$ gosub Init\n$!\n$ man2help sys$input: libssh2.hlp -b 1\n\nLIBSSH2\n\nOpenVMS port of the public domain libssh2 library, which \nprovides an API to implement client SSH communciation.\n\nLicense information is available at the copying subtopic.\n\n$!\n$ open\/append mh libssh2.hlp\n$ write mh helpversion\n$ close mh\n$!\n$ man2help -a [-]readme.; libssh2.hlp -b 2\n$ man2help -a [-]authors.; libssh2.hlp -b 2\n$ man2help -a [-]copying.; libssh2.hlp -b 2\n$ man2help -a [-]news.; libssh2.hlp -b 2\n$ man2help -a [-]release-notes.; libssh2.hlp -b 2\n$ man2help -a [-]hacking.; libssh2.hlp -b 2\n$ man2help -a [-]todo.; libssh2.hlp -b 2\n$!\n$ man2help -a sys$input: libssh2.hlp -b 2\n\nAPI_Reference\n\nReference of all implemented API calls in\nlibssh2.\n\n$!\n$ man2help -a [-.docs]*.3 libssh2.hlp -b 3 -p\n$!\n$ library\/help\/create libssh2.hlb libssh2.hlp\n$!\n$End:\n$ set default 'olddir'\n$exit\n$!\n$!-------------------------------------------------------\n$!\n$Init:\n$!\n$ thisdir = f$environment( \"procedure\" )\n$ thisdir = f$parse(thisdir,,,\"device\") + f$parse(thisdir,,,\"directory\")\n$ set default 'thisdir'\n$! \n$ say = \"write sys$output\"\n$!\n$ pipe search [-.include]*.h libssh2_version_major\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job majorv &l )\n$ pipe search [-.include]*.h libssh2_version_minor\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job minorv &l )\n$ pipe search [-.include]*.h libssh2_version_patch\/nohead | (read sys$input l ; l = f$element(2,\" \",f$edit(l,\"trim,compress\")) ; - \n define\/job patchv &l )\n$!\n$ majorv = f$trnlnm(\"majorv\")\n$ minorv = f$integer(f$trnlnm(\"minorv\")) \n$ patchv = f$integer( f$trnlnm(\"patchv\"))\n$!\n$ helpversion = \"This help library is based on build version ''majorv'.''minorv'.''patchv' of libssh2.\"\n$!\n$ deassign\/job majorv\n$ deassign\/job minorv\n$ deassign\/job patchv\n$!\n$ if f$search( \"man2help.exe\" ) .eqs. \"\"\n$ then\n$ cc man2help\n$ link man2help\n$ endif\n$! \n$ man2help := $'thisdir'man2help.exe \n$!\n$ if f$search(\"libssh2.hlp\") .nes. \"\" \n$ then \n$ delete libssh2.hlp;*\n$ endif\n$ if f$search(\"libssh2.hlb\") .nes. \"\" \n$ then \n$ delete libssh2.hlb;*\n$ endif\n$return\n","returncode":0,"stderr":"","license":"bsd-3-clause","lang":"Clean"} {"commit":"ed7895d2f0d8b5653ef74d3be21a3136d2acbd42","subject":"Typo","message":"Typo\n\ngit-svn-id: 152f48a1866dc7886cc2b83d2001e6645df26423@1004503 13f79535-47bb-0310-9956-ffa450edef68\n","repos":"apache\/commons-exec,sgoeschl\/commons-exec,apache\/commons-exec,mohanaraosv\/commons-exec,mohanaraosv\/commons-exec,sgoeschl\/commons-exec","old_file":"src\/test\/scripts\/stdin.dcl","new_file":"src\/test\/scripts\/stdin.dcl","new_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Licensed to the Apache Software Foundation (ASF) under one or more\n$! contributor license agreements. See the NOTICE file distributed with\n$! this work for additional information regarding copyright ownership.\n$! The ASF licenses this file to You under the Apache License, Version 2.0\n$! (the \"License\"); you may not use this file except in compliance with\n$! the License. You may obtain a copy of the License at\n$!\n$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n$!\n$! Unless required by applicable law or agreed to in writing, software\n$! distributed under the License is distributed on an \"AS IS\" BASIS,\n$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n$! See the License for the specific language governing permissions and\n$! limitations under the License.\n$! \n$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Read input and display it\n$!\n$ read \/prompt=\"What's your name? : \" sys$command answer\n$ write sys$output \"Hello ''answer'!\"","old_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Licensed to the Apache Software Foundation (ASF) under one or more\n$! contributor license agreements. See the NOTICE file distributed with\n$! this work for additional information regarding copyright ownership.\n$! The ASF licenses this file to You under the Apache License, Version 2.0\n$! (the \"License\"); you may not use this file except in compliance with\n$! the License. You may obtain a copy of the License at\n$!\n$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n$!\n$! Unless required by applicable law or agreed to in writing, software\n$! distributed under the License is distributed on an \"AS IS\" BASIS,\n$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n$! See the License for the specific language governing permissions and\n$! limitations under the License.\n$! \n$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Read input and display is\n$!\n$ read \/prompt=\"What's your name? : \" sys$command answer\n$ write sys$output \"Hello ''answer'!\"","returncode":0,"stderr":"","license":"apache-2.0","lang":"Clean"} {"commit":"b7ff71b351525e260aca55356d36675a6058a293","subject":"Use new hyperstrict instead of copied eval_all_nodes","message":"Use new hyperstrict instead of copied eval_all_nodes\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o, seq\nfrom StdMisc import undef\nimport StdOrdList\nimport StdOverloaded\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable, instance Foldable Maybe\nfrom Data.Func import $, hyperstrict\nimport Data.Functor\nimport Data.List\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_include_apps = fromJust (r.include_apps <|> Just DEFAULT_INCLUDE_APPS)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDb f\n#! db = hyperstrict db\n#! w = if opts.reload_cache (reloadCache db) id w\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle db\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !CloogleDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle db Nothing w = (err InvalidInput \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond {r & return = if (r.return == 0) 1 r.return} w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err InvalidName \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err InvalidName \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err InvalidType \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! results = drop drop_n $ sort $ search request db\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! suggestions = unify >>= parseType o fromString >>= flip (suggs name) db\n\t\t#! w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- 'Foldable'.concat suggestions] w\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: !Response !*World -> *(!Response, !CacheKey, !*World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !CloogleDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\treloadCache :: !CloogleDB !*World -> *World\n\treloadCache db w\n\t# (keys,w) = allCacheKeys LongTerm w\n\t# w = search (map fromRequestCacheKey keys) w\n\t= w\n\twhere\n\t\tsearch :: ![Request] !*World -> *World\n\t\tsearch [] w = w\n\t\tsearch [r:rs] w = search rs $ thd3 $ handle db (Just r) w\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o, seq\nfrom StdMisc import undef\nimport StdOrdList\nimport StdOverloaded\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable, instance Foldable Maybe\nfrom Data.Func import $\nimport Data.Functor\nimport Data.List\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat), instance Text String, <+\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_include_apps = fromJust (r.include_apps <|> Just DEFAULT_INCLUDE_APPS)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDb f\n#! db = eval_all_nodes db\n#! w = if opts.reload_cache (reloadCache db) id w\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle db\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\teval_all_nodes :: !.a -> .a \/\/ From GraphCopy\n\teval_all_nodes g = code {\n\t\tpush_a 0\n\t\t.d 1 0\n\t\tjsr\t_eval_to_nf\n\t\t.o 0 0\n\t}\n\n\thandle :: !CloogleDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle db Nothing w = (err InvalidInput \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond {r & return = if (r.return == 0) 1 r.return} w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err InvalidName \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err InvalidName \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err InvalidType \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! results = drop drop_n $ sort $ search request db\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! suggestions = unify >>= parseType o fromString >>= flip (suggs name) db\n\t\t#! w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- 'Foldable'.concat suggestions] w\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: !Response !*World -> *(!Response, !CacheKey, !*World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !CloogleDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\treloadCache :: !CloogleDB !*World -> *World\n\treloadCache db w\n\t# (keys,w) = allCacheKeys LongTerm w\n\t# w = search (map fromRequestCacheKey keys) w\n\t= w\n\twhere\n\t\tsearch :: ![Request] !*World -> *World\n\t\tsearch [] w = w\n\t\tsearch [r:rs] w = search rs $ thd3 $ handle db (Just r) w\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"cee40e901656c6e0c0482d1a9ead06af0c2a62ef","subject":"max already defined","message":"max already defined\n","repos":"dkm\/gcc-explorer,mattgodbolt\/gcc-explorer,dkm\/gcc-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/compiler-explorer,dkm\/gcc-explorer,mattgodbolt\/compiler-explorer,dkm\/gcc-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/gcc-explorer,mattgodbolt\/gcc-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/compiler-explorer,dkm\/gcc-explorer,dkm\/gcc-explorer,dkm\/gcc-explorer,dkm\/gcc-explorer,dkm\/gcc-explorer,mattgodbolt\/gcc-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/gcc-explorer","old_file":"examples\/clean\/Max_array.icl","new_file":"examples\/clean\/Max_array.icl","new_contents":"module example\n\nimport StdEnv\n\nmaxArray :: [Real] [Real] -> [Real]\nmaxArray list1 list2\n = [ (max e1 e2)\n \\\\ e1 <- list1\n & e2 <- list2\n ]\n\nStart :: [Real]\nStart = maxArray [1.3,4.1,6.6,2.3,3.5] [2.1,3.3,88.9,-5.0,3.56]\n","old_contents":"module example\n\nimport StdEnv\n\nmax :: Real Real -> Real\nmax a b\n= if (a>=b) a b\n\nmaxArray :: [Real] [Real] -> [Real]\nmaxArray list1 list2\n = [ (max e1 e2)\n \\\\ e1 <- list1\n & e2 <- list2\n ]\n\nStart :: [Real]\nStart = maxArray [1.3,4.1,6.6,2.3,3.5] [2.1,3.3,88.9,-5.0,3.56]\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Clean"} {"commit":"fe39bdab7033255fbac1e63c721819ef46b631ed","subject":"bugfix clean example file","message":"bugfix clean example file\n","repos":"mattgodbolt\/compiler-explorer,dkm\/gcc-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/gcc-explorer,dkm\/gcc-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/gcc-explorer,dkm\/gcc-explorer,mattgodbolt\/gcc-explorer,mattgodbolt\/compiler-explorer,dkm\/gcc-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/gcc-explorer,dkm\/gcc-explorer,dkm\/gcc-explorer,mattgodbolt\/gcc-explorer,dkm\/gcc-explorer,dkm\/gcc-explorer,mattgodbolt\/compiler-explorer,mattgodbolt\/compiler-explorer,dkm\/gcc-explorer,mattgodbolt\/compiler-explorer","old_file":"examples\/clean\/qsort.icl","new_file":"examples\/clean\/qsort.icl","new_contents":"module example\n\nimport StdEnv\n\nqsort :: [Int] -> [Int]\nqsort [] = []\nqsort [p:l] = (qsort [x \\\\ x<-l | x=p])\n\nStart :: [Int]\nStart = qsort [3,5,1,4,2]\n","old_contents":"module test\n\nimport StdEnv\n\nqsort :: [Int] -> [Int]\nqsort [] = []\nqsort [p:l] = (qsort [x \\\\ x<-l | x=p])\n\nStart :: [Int]\nStart = qsort [3,5,1,4,2]\n","returncode":0,"stderr":"","license":"bsd-2-clause","lang":"Clean"} {"commit":"bf0eb3c96cb08a096a73ca177567b9935ef1c109","subject":"Fix pattern for binumap addition (#213); copy edited text","message":"Fix pattern for binumap addition (#213); copy edited text\n","repos":"clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_basicvalues\n\t, bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_basicvalues =\n\t{ syntax_title = \"basic values\"\n\t, syntax_patterns = map exact [\"'.'\", \"[+-]?\\\\d+\", \"[+-]?0[0-7]+\", \"[-+]?0x[0-9a-fA-F]+\", \"E\"]\n\t, syntax_code = [\"0x...\", \"0...\", \"'...'\", \"...E...\"]\n\t, syntax_description =\n\t\t\"Constant basic values can be of type {{`Int`}}, {{`Char`}} and {{`Real`}}. See also {{`Bool`}}.\\n\\n\" +\n\t\t\"Integers can be specified in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix) notation.\\n\\n\" +\n\t\t\"Characters can either be printable characters (except `'`) or an escape sequence.\\n\" +\n\t\t\"An escape sequence is a character escape, a hexademical escape (starting with `x`), an octal escape (starting with `0` to `7`) or a decimal escape (starting with `d`).\\n\\n\" +\n\t\t\"Reals can be suffixed by a power of ten in the scientific notation.\\n\\n\" +\n\t\t\"Basic values can also be pattern matched with these notations.\"\n\t, syntax_doc_locations = [CLR 6 \"4.1.1\" \"_Toc311798017\"]\n\t, syntax_examples = map (EXs \"rhs\")\n\t\t[ \"(42, -42, +42) \/\/ Tuple with 42, -42 and 42 in decimal notation\"\n\t\t, \"(052, -052, +052) \/\/ Tuple with 42, -42 and 42 in octal notation\"\n\t\t, \"(0x2a, -0x2a, +0x2A) \/\/ Tuple with 42, -42 and 42 in hexadecimal notation\"\n\t\t, \"('a', '\\\\x2a', '\\\\052') \/\/ Tuple with a normal character and twice the character with ASCII value 42\"\n\t\t, \"['\\\\n', '\\\\r', '\\\\f', '\\\\b', '\\\\t', '\\\\v', '\\\\', '\\\\'', '\\\\\\\"']\\n\" +\n\t\t \" \/\/ All character escapes\"\n\t\t, \"(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\\n\" +\n\t\t \" \/\/ Several reals\"\n\t\t]\n\t}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\", \"\\\\*\/\", \"comments?\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\", \"\\\\*!\"]\n\t, syntax_code = [\"generic ... ... [| ...] [*!] :: ... \", \"derive ... ... [of ...] [with ...]\"]\n\t, syntax_description = join \" \"\n\t\t[ \"With generics, a function can be defined once and derived for (almost) all possible types.\"\n\t\t, \"This avoids very similar code snippets.\"\n\t\t, \"Generic functions are said to be kind-indexed, i.e., a generic is actually a group of functions with different types depending on the kind of the deriving type.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples = map EX\n\t\t[ \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, \"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context. The context will become an argument.\\n\" +\n\t\t \"derive gFun CONS of {gcd_arity} with f _ \/\/ A derivation that does not use all arguments. The compiler can optimize even more.\\n\" +\n\t\t \"gFun{|CONS of {gcd_arity}|} f _ = \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t, \"generic gShared a *! :: ... \/\/ A generic function that will use a bimap without uniqueness attributes (very experimental, see https:\/\/gitlab.science.ru.nl\/clean-and-itasks\/clean-language-report\/blob\/master\/experimental\/binumap.md).\\n\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t, \"abc ['abc':rest] = True \/\/ The special syntax can als be used to patternmatch\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_basicvalues\n\t, bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_basicvalues =\n\t{ syntax_title = \"basic values\"\n\t, syntax_patterns = map exact [\"'.'\", \"[+-]?\\\\d+\", \"[+-]?0[0-7]+\", \"[-+]?0x[0-9a-fA-F]+\", \"E\"]\n\t, syntax_code = [\"0x...\", \"0...\", \"'...'\", \"...E...\"]\n\t, syntax_description =\n\t\t\"Constant basic values can be of type {{`Int`}}, {{`Char`}} and {{`Real`}}. See also {{`Bool`}}.\\n\\n\" +\n\t\t\"Integers can be specified in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix) notation.\\n\\n\" +\n\t\t\"Characters can either be printable characters (except `'`) or an escape sequence.\\n\" +\n\t\t\"An escape sequence is a character escape, a hexademical escape (starting with `x`), an octal escape (starting with `0` to `7`) or a decimal escape (starting with `d`).\\n\\n\" +\n\t\t\"Reals can be suffixed by a power of ten in the scientific notation.\\n\\n\" +\n\t\t\"Basic values can also be pattern matched with these notations.\"\n\t, syntax_doc_locations = [CLR 6 \"4.1.1\" \"_Toc311798017\"]\n\t, syntax_examples = map (EXs \"rhs\")\n\t\t[ \"(42, -42, +42) \/\/ Tuple with 42, -42 and 42 in decimal notation\"\n\t\t, \"(052, -052, +052) \/\/ Tuple with 42, -42 and 42 in octal notation\"\n\t\t, \"(0x2a, -0x2a, +0x2A) \/\/ Tuple with 42, -42 and 42 in hexadecimal notation\"\n\t\t, \"('a', '\\\\x2a', '\\\\052') \/\/ Tuple with a normal character and twice the character with ASCII value 42\"\n\t\t, \"['\\\\n', '\\\\r', '\\\\f', '\\\\b', '\\\\t', '\\\\v', '\\\\', '\\\\'', '\\\\\\\"']\\n\" +\n\t\t \" \/\/ All character escapes\"\n\t\t, \"(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\\n\" +\n\t\t \" \/\/ Several reals\"\n\t\t]\n\t}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\", \"\\\\*\/\", \"comments?\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\", \"*!\"]\n\t, syntax_code = [\"generic ... ... [| ...] [*!] :: ... \", \"derive ... ... [of ...] [with ...]\"]\n\t, syntax_description = \"With generics, a kind indexed function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples = map EX\n\t\t[ \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, \"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context. The context will become an argument.\\n\" +\n\t\t \"derive gFun CONS of {gcd_arity} with f _ \/\/ A derivation that does not use all arguments. The compiler can optimize even more.\\n\" +\n\t\t \"gFun{|CONS of {gcd_arity}|} f _ = \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t, \"generic gShared a *! :: ... \/\/ Derive a generic function using a shared bimap (very experimental, see https:\/\/gitlab.science.ru.nl\/clean-and-itasks\/clean-language-report\/blob\/master\/experimental\/binumap.md).\\n\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t, \"abc ['abc':rest] = True \/\/ The special syntax can als be used to patternmatch\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"e4c702edaf91dee0e2a41dca61c55ae676f2ba0c","subject":"fix brackets, title and document location","message":"fix brackets, title and document location\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_basicvalues\n\t, bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_basicvalues =\n\t{ syntax_title = \"basic values\"\n\t, syntax_patterns = map exact [\"'.'\", \"[+-]?\\\\d+\", \"[+-]?0[0-7]+\", \"[-+]?0x[0-9a-fA-F]+\", \"'.'\", \"True\", \"False\", \"E\"]\n\t, syntax_code = [\"0x...\", \"0...\", \"True\", \"False\", \"'...'\", \"...E...\"]\n\t, syntax_description =\n\t\t\"Constant basic values can be of type Int, Char, Real and Bool.\\n\\n\" +\n\t\t\"Integers can be either defined in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix).\\n\\n\" +\n\t\t\"Characters can either be printable characters (except `'`) or an escape sequence.\\n\\n\" +\n\t\t\"Reals can be suffixed by a power of ten in the scientific notation.\\n\\n\" +\n\t\t\"Boolean values by their only inhabitants {{`True`}} and {{`False`}}.\\n\\n\" +\n\t\t\"Basic values can also be pattern matched with these notations.\"\n\t, syntax_doc_locations = [CLR 4 \"4.1.1\" \"_Toc311798017\"]\n\t, syntax_examples = map EX\n\t\t[ \"(42, -42, +42) \/\/ Tuple with 42, -42 and 42 in decimal\"\n\t\t, \"(052, -052, +052) \/\/ Tuple with 42, -42 and 42 in octal\"\n\t\t, \"(0x2a, -0x2a, +0x2A) \/\/ Tuple with 42, -42 and 42 in hexadecimal\"\n\t\t, \"('a', '\\\\x2a', '\\\\052') \/\/ Tuple with a normal character, a literal quote and twice the character with ordinal 42\"\n\t\t, \"['\\\\n', '\\\\r', '\\\\f', '\\\\b', '\\\\t', '\\\\', '\\'']\\n\" +\n\t\t \" \/\/ All character escapes\"\n\t\t, \"(True, False) \/\/ All booleans in a tuple\"\n\t\t, \"(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\\n\" +\n\t\t \" \/\/ Several reals\"\n\t\t]\n\t}\n\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... [| ...] :: ... \", \"derive ... ... [of ... [with ...]]\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, EX \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, EXs \"macro\" $ \"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context\\n\" +\n\t\t \"gFun{|CONS of {gcd_arity}|} with f _ \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t, \"abc ['abc':rest] = True \/\/ The special syntax can als be used to patternmatch\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_basicvalues\n\t, bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_basicvalues =\n\t{ syntax_title = \"basicvalues\"\n\t, syntax_patterns = map exact [\"'.'\", \"[+-]?\\\\d+\", \"[+-]?0[0-7]+\", \"[-+]?0x[0-9a-fA-F]+\", \"'.'\", \"True\", \"False\", \"E\"]\n\t, syntax_code = [\"0x...\", \"0...\", \"True\", \"False\", \"'...'\", \"...E...\"]\n\t, syntax_description =\n\t\t\"Constant basic values can be of type Int, Char, Real and Bool.\\n\\n\" +\n\t\t\"Integers can be either defined in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix).\\n\\n\" +\n\t\t\"Characters can either be printable characters (except `'`) or an escape sequence.\\n\\n\" +\n\t\t\"Reals can be suffixed by a power of ten in the scientific notation.\\n\\n\" +\n\t\t\"Boolean values by their only inhabitants {{True}} and {{False}}.\\n\\n\" +\n\t\t\"Basic values can also be pattern matched with these notations.\"\n\t, syntax_doc_locations = [CLR 4 \"1.1\" \"_Toc311798017\"]\n\t, syntax_examples = map EX\n\t\t[ \"(42, -42, +42) \/\/ Tuple with 42, -42 and 42 in decimal\"\n\t\t, \"(052, -052, +052) \/\/ Tuple with 42, -42 and 42 in octal\"\n\t\t, \"(0x2a, -0x2a, +0x2A) \/\/ Tuple with 42, -42 and 42 in hexadecimal\"\n\t\t, \"('a', '\\\\x2a', '\\\\052') \/\/ Tuple with a normal character, a literal quote and twice the character with ordinal 42\"\n\t\t, \"['\\\\n', '\\\\r', '\\\\f', '\\\\b', '\\\\t', '\\\\', '\\'']\\n\" +\n\t\t \" \/\/All character escapes\"\n\t\t, \"(True, False) \/\/ All booleans in a tuple\"\n\t\t, \"(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\\n\" +\n\t\t \" \/\/Several reals\"\n\t\t]\n\t}\n\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... [| ...] :: ... \", \"derive ... ... [of ... [with ...]]\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, EX \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, EXs \"macro\" $ \"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context\\n\" +\n\t\t \"gFun{|CONS of {gcd_arity}|} with f _ \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t, \"abc ['abc':rest] = True \/\/ The special syntax can als be used to patternmatch\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"a7d79746c15ce4ab366b81f5849e46f8c9fc88a4","subject":"Timestamps in log","message":"Timestamps in log\n","repos":"dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle","old_file":"CloogleServer.icl","new_file":"CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdEnv\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.Maybe\nimport System.CommandLine\nimport Text\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nfrom Control.Monad import class Monad(..)\nimport Text\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Command = { unify :: String\n , name :: String\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n }\n\n:: Result = { library :: String\n , filename :: String\n , func :: String\n , cls :: Maybe ClassResult\n , modul :: String\n , distance :: Int\n }\n\n:: ErrorResult = Error Int String\n\n:: ClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Command, Response, Result, ClassResult\nderive JSONDecode Command, Response, Result, ClassResult\n\ninstance toString Response where toString r = toString $ toJSON r\ninstance toString Command where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Command) where fromString s = fromJSON $ fromString s\n\ninstance < Result where (<) r1 r2 = r1.distance < r2.distance\n\nerr :: Int String -> Response\nerr c m = {return=c, data=[], msg=m}\n\nMAX_RESULTS :== 100\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n# db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: TypeDB (Maybe Command) *World -> *(Response, *World)\n\thandle _ Nothing w = (err 4 \"Couldn't parse input\", w)\n\thandle db (Just {unify,name}) w\n\t\t# mbType = parseType (fromString unify)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes $ [ (\\t->(\\_ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\loc _ ->\n\t\t isNameMatch (size name-2) name loc)\n\t\t ]\n\t\t# funcs = map (makeResult name mbType Nothing) $ findType`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes $ [ (\\t->(\\_ _ _ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\(CL lib mod _) _ f _ ->\n\t\t isNameMatch (size name-2) name (FL lib mod f))\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,f,t) -> makeResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,t)) members\n\t\t# results = take MAX_RESULTS $ sort $ funcs ++ members\n\t\t= ({return=0,msg=\"Success\",data=results}, w)\n\n\tmakeResult :: String (Maybe Type) (Maybe ClassResult)\n\t (FunctionLocation, Type) -> Result\n\tmakeResult orgsearch orgsearchtype mbCls (FL lib mod fname, type)\n\t\t= { library = lib\n\t\t , filename = (toString $ reverse $ takeWhile ((<>)'.')\n\t\t $ reverse $ fromString mod) +++ \".dcl\"\n\t\t , modul = mod\n\t\t , func = fname +++ \" :: \" +++ concat (stripParens $ print type)\n\t\t , cls = mbCls\n\t\t , distance = distance\n\t\t }\n\twhere\n\t\tstripParens :: [String] -> [String]\n\t\tstripParens [\"(\":ss]\n\t\t\t| last ss == \")\" && parensMatch 0 (init ss) = stripParens $ init ss\n\t\t\t| otherwise = [\"(\":ss]\n\t\tstripParens ss = ss\n\n\t\tparensMatch :: Int [String] -> Bool\n\t\tparensMatch 0 [] = True\n\t\tparensMatch _ [] = False\n\t\tparensMatch i [\"(\":ss] = i >= 0 && parensMatch (i+1) ss\n\t\tparensMatch i [\")\":ss] = i >= 0 && parensMatch (i-1) ss\n\t\tparensMatch i [_:ss] = i >= 0 && parensMatch i ss\n\n\t\tdistance\n\t\t\t| orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = unify [] orgsearchtype type\n\t\t\t\t= length $ filter (not o isVar o snd) $ ass1 ++ ass2\n\t\t\t# levdist = levenshtein fname orgsearch\n\t\t\t= if (indexOf orgsearch fname == -1) 0 -100 + levdist\n\n\tisUnifiable :: Type Type -> Bool\n\tisUnifiable t1 t2 = isJust (unify [] t1 t2)\n\n\tisNameMatch :: Int String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tlog :: (LogMessage (Maybe Command) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Command) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Command) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent {return,data,msg}) ip\n\t\t= toString ip +++ \" --> \" +++ toString (length data) +++ \" results (\"\n\t\t\t+++ toString return +++ \"; \" +++ msg +++ \")\\n\"\n\tmsgToString _ _ = \"\"\n\n","old_contents":"module CloogleServer\n\nimport StdEnv\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.Maybe\nimport System.CommandLine\nimport Text\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nfrom Control.Monad import class Monad(..)\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Command = { unify :: String\n , name :: String\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n }\n\n:: Result = { library :: String\n , filename :: String\n , func :: String\n , cls :: Maybe ClassResult\n , modul :: String\n , distance :: Int\n }\n\n:: ErrorResult = Error Int String\n\n:: ClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Command, Response, Result, ClassResult\nderive JSONDecode Command, Response, Result, ClassResult\n\ninstance toString Response where toString r = toString $ toJSON r\ninstance toString Command where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Command) where fromString s = fromJSON $ fromString s\n\ninstance < Result where (<) r1 r2 = r1.distance < r2.distance\n\nerr :: Int String -> Response\nerr c m = {return=c, data=[], msg=m}\n\nMAX_RESULTS :== 100\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n# db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: TypeDB (Maybe Command) *World -> *(Response, *World)\n\thandle _ Nothing w = (err 4 \"Couldn't parse input\", w)\n\thandle db (Just {unify,name}) w\n\t\t# mbType = parseType (fromString unify)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes $ [ (\\t->(\\_ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\loc _ ->\n\t\t isNameMatch (size name-2) name loc)\n\t\t ]\n\t\t# funcs = map (makeResult name mbType Nothing) $ findType`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes $ [ (\\t->(\\_ _ _ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\(CL lib mod _) _ f _ ->\n\t\t isNameMatch (size name-2) name (FL lib mod f))\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,f,t) -> makeResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,t)) members\n\t\t# results = take MAX_RESULTS $ sort $ funcs ++ members\n\t\t= ({return=0,msg=\"Success\",data=results}, w)\n\n\tmakeResult :: String (Maybe Type) (Maybe ClassResult)\n\t (FunctionLocation, Type) -> Result\n\tmakeResult orgsearch orgsearchtype mbCls (FL lib mod fname, type)\n\t\t= { library = lib\n\t\t , filename = (toString $ reverse $ takeWhile ((<>)'.')\n\t\t $ reverse $ fromString mod) +++ \".dcl\"\n\t\t , modul = mod\n\t\t , func = fname +++ \" :: \" +++ concat (stripParens $ print type)\n\t\t , cls = mbCls\n\t\t , distance = distance\n\t\t }\n\twhere\n\t\tstripParens :: [String] -> [String]\n\t\tstripParens [\"(\":ss]\n\t\t\t| last ss == \")\" && parensMatch 0 (init ss) = stripParens $ init ss\n\t\t\t| otherwise = [\"(\":ss]\n\t\tstripParens ss = ss\n\n\t\tparensMatch :: Int [String] -> Bool\n\t\tparensMatch 0 [] = True\n\t\tparensMatch _ [] = False\n\t\tparensMatch i [\"(\":ss] = i >= 0 && parensMatch (i+1) ss\n\t\tparensMatch i [\")\":ss] = i >= 0 && parensMatch (i-1) ss\n\t\tparensMatch i [_:ss] = i >= 0 && parensMatch i ss\n\n\t\tdistance\n\t\t\t| orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = unify [] orgsearchtype type\n\t\t\t\t= length $ filter (not o isVar o snd) $ ass1 ++ ass2\n\t\t\t# levdist = levenshtein fname orgsearch\n\t\t\t= if (indexOf orgsearch fname == -1) 0 -100 + levdist\n\n\tisUnifiable :: Type Type -> Bool\n\tisUnifiable t1 t2 = isJust (unify [] t1 t2)\n\n\tisNameMatch :: Int String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tlog :: (LogMessage (Maybe Command) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t# (io,w) = stdio w\n\t# io = fwrites (msgToString msg s) io\n\t= (newS msg s, snd (fclose io w))\n\n\tnewS :: (LogMessage (Maybe Command) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Command) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent {return,data,msg}) ip\n\t\t= toString ip +++ \" --> \" +++ toString (length data) +++ \" results (\"\n\t\t\t+++ toString return +++ \"; \" +++ msg +++ \")\\n\"\n\tmsgToString _ _ = \"\"\n\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"337beddd3f77ed48cd4b8477a5b4c2b444f89c69","subject":"Document .n and .nu ABC directives","message":"Document .n and .nu ABC directives\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/ABC.icl","new_file":"backend\/Builtin\/ABC.icl","new_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \"- sep can be either `-` or `:`.\"\n\t\t\t, \"- flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \"- input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t\t, \"- output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t\t, \"- state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \"- `I` for integers\"\n\t\t\t, \"- `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \"- [`Rr`] for reals\"\n\t\t\t, \"- `S` for Clean Strings (`{#Char}`).\"\n\t\t\t, \"- `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}})\"\n\t\t\t, \"- `A` for A-stack elements (e.g. used for `*World`, a boxed integer under the hood)\"\n\t\t\t, \"- [`OF`] for function pointers\"\n\t\t\t, \"- `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_n\n\t, d_nu\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_n =\n\t\t{ zero\n\t\t& aie_instruction = \".n\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t, \"\\n\\nThere are some special cases:\\n\\n\"\n\t\t\t, \"- An arity of `-1` is for tuple selectors;\\n\"\n\t\t\t, \"- An arity of `-2` is for indirection nodes;\\n\"\n\t\t\t, \"- An arity of `-3` is for record selectors of basic types;\\n\"\n\t\t\t, \"- An arity of `-4` is for record selectors of non-basic types.\\n\\n\"\n\t\t\t, \"See also {{`.nu`}}.\"\n\t\t\t]\n\t\t}\n\td_nu =\n\t\t{ zero\n\t\t& aie_instruction = \".nu\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels with arguments on the B-stack (otherwise, {{`.n`}} is used).\"\n\t\t\t, \"The first integer is the number of A-stack arguments; the second the number of B-stack arguments.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_a_b\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_t_r_a\"\n\t, \"push_t_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_t\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","old_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \"- sep can be either `-` or `:`.\"\n\t\t\t, \"- flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \"- input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t\t, \"- output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t\t, \"- state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \"- `I` for integers\"\n\t\t\t, \"- `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \"- [`Rr`] for reals\"\n\t\t\t, \"- `S` for Clean Strings (`{#Char}`).\"\n\t\t\t, \"- `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}})\"\n\t\t\t, \"- `A` for A-stack elements (e.g. used for `*World`, a boxed integer under the hood)\"\n\t\t\t, \"- [`OF`] for function pointers\"\n\t\t\t, \"- `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_a_b\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_t_r_a\"\n\t, \"push_t_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_t\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".n\"\n\t, \".nu\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"a608190a76e7699bdda5df0de37b5c32bc8210a0","subject":"Proposal for #10: sorting on assignment complexity","message":"Proposal for #10: sorting on assignment complexity\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"CloogleServer.icl","new_file":"CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf), instance Text String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: String\n , name :: String\n , modules :: Maybe [String]\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n }\n\n:: Result = { library :: String\n , filename :: String\n , func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ClassResult\n , modul :: String\n , distance :: Int\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ClassResult\nderive JSONDecode Request, Response, Result, ClassResult\n\ninstance toString Response where toString r = toString $ toJSON r\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < Result where (<) r1 r2 = r1.distance < r2.distance\n\nerr :: Int String -> Response\nerr c m = {return=c, data=[], msg=m, more_available=Nothing}\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n# db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: TypeDB (Maybe Request) *World -> *(Response, *World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just {unify,name,modules,page}) w\n\t\t# mbType = parseType (fromString unify)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes $ [ (\\t->(\\_ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\loc _ ->\n\t\t isNameMatch (size name-2) name loc)\n\t\t , isModMatchF <$> modules\n\t\t ]\n\t\t# funcs = map (makeResult name mbType Nothing) $ findType`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes $ [ (\\t->(\\_ _ _ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\(CL lib mod _) _ f _ ->\n\t\t isNameMatch (size name-2) name (FL lib mod f))\n\t\t , isModMatchC <$> modules\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,f,et) -> makeResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,et)) members\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ funcs ++ members\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t# results = take MAX_RESULTS results\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ({return=0,msg=\"Success\",data=results,more_available=Just more}, w)\n\n\tmakeResult :: String (Maybe Type) (Maybe ClassResult)\n\t (FunctionLocation, ExtendedType) -> Result\n\tmakeResult orgsearch orgsearchtype mbCls (FL lib mod fname, ET type tes)\n\t\t= { library = lib\n\t\t , filename = (toString $ reverse $ takeWhile ((<>)'.')\n\t\t $ reverse $ fromString mod) +++ \".dcl\"\n\t\t , modul = mod\n\t\t , func = fname +++ toStrPriority tes.te_priority +++\n\t\t\t\t\t \" :: \" +++ concat (stripParens $ print type)\n\t\t , unifier = toStrUnifier <$> (orgsearchtype >>= unify [] type)\n\t\t , cls = mbCls\n\t\t , distance = distance\n\t\t }\n\twhere\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tstripParens :: [String] -> [String]\n\t\tstripParens [\"(\":ss]\n\t\t\t| last ss == \")\" && parensMatch 0 (init ss) = stripParens $ init ss\n\t\t\t| otherwise = [\"(\":ss]\n\t\tstripParens ss = ss\n\n\t\tparensMatch :: Int [String] -> Bool\n\t\tparensMatch 0 [] = True\n\t\tparensMatch _ [] = False\n\t\tparensMatch i [\"(\":ss] = i >= 0 && parensMatch (i+1) ss\n\t\tparensMatch i [\")\":ss] = i >= 0 && parensMatch (i-1) ss\n\t\tparensMatch i [_:ss] = i >= 0 && parensMatch i ss\n\n\t\tdistance\n\t\t\t| orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = unify [] orgsearchtype type\n\t\t\t\t= sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)]\n\t\t\t# levdist = levenshtein fname orgsearch\n\t\t\t= if (indexOf orgsearch fname == -1) 0 -100 + levdist\n\t\twhere\n\t\t\ttypeComplexity :: Type -> Int\n\t\t\ttypeComplexity (Type _ ts) = foldr ((+) o typeComplexity) 1 ts\n\t\t\ttypeComplexity (Func is _ _) = foldr ((+) o typeComplexity) 5 is\n\t\t\ttypeComplexity (Var _) = 1\n\t\t\ttypeComplexity (Cons _ ts) = foldr ((+) o typeComplexity) 1 ts\n\t\t\ttypeComplexity (Uniq t) = 3 + typeComplexity t\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 t2)\n\n\tisNameMatch :: !Int !String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatchF :: ![String] FunctionLocation ExtendedType -> Bool\n\tisModMatchF mods (FL _ mod _) _ = isMember mod mods\n\n\tisModMatchC :: ![String] ClassLocation [TypeVar] FunctionName ExtendedType -> Bool\n\tisModMatchC mods (CL _ mod _) _ _ _ = isMember mod mods\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip +++ \" --> \" +++ toString (length data) +++ \" results (\"\n\t\t\t+++ toString return +++ \"; \" +++ msg +++\n\t\t\tif (isJust more_available) (\"; \" +++ toString (fromJust more_available) +++ \" more\") \"\" +++ \")\\n\"\n\tmsgToString _ _ = \"\"\n\n","old_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf), instance Text String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: String\n , name :: String\n , modules :: Maybe [String]\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n }\n\n:: Result = { library :: String\n , filename :: String\n , func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ClassResult\n , modul :: String\n , distance :: Int\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ClassResult\nderive JSONDecode Request, Response, Result, ClassResult\n\ninstance toString Response where toString r = toString $ toJSON r\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < Result where (<) r1 r2 = r1.distance < r2.distance\n\nerr :: Int String -> Response\nerr c m = {return=c, data=[], msg=m, more_available=Nothing}\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n# db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: TypeDB (Maybe Request) *World -> *(Response, *World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just {unify,name,modules,page}) w\n\t\t# mbType = parseType (fromString unify)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes $ [ (\\t->(\\_ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\loc _ ->\n\t\t isNameMatch (size name-2) name loc)\n\t\t , isModMatchF <$> modules\n\t\t ]\n\t\t# funcs = map (makeResult name mbType Nothing) $ findType`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes $ [ (\\t->(\\_ _ _ u->isUnifiable t u)) <$> mbType\n\t\t , pure (\\(CL lib mod _) _ f _ ->\n\t\t isNameMatch (size name-2) name (FL lib mod f))\n\t\t , isModMatchC <$> modules\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,f,et) -> makeResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,et)) members\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ funcs ++ members\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t# results = take MAX_RESULTS results\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ({return=0,msg=\"Success\",data=results,more_available=Just more}, w)\n\n\tmakeResult :: String (Maybe Type) (Maybe ClassResult)\n\t (FunctionLocation, ExtendedType) -> Result\n\tmakeResult orgsearch orgsearchtype mbCls (FL lib mod fname, ET type tes)\n\t\t= { library = lib\n\t\t , filename = (toString $ reverse $ takeWhile ((<>)'.')\n\t\t $ reverse $ fromString mod) +++ \".dcl\"\n\t\t , modul = mod\n\t\t , func = fname +++ toStrPriority tes.te_priority +++\n\t\t\t\t\t \" :: \" +++ concat (stripParens $ print type)\n\t\t , unifier = toStrUnifier <$> (orgsearchtype >>= unify [] type)\n\t\t , cls = mbCls\n\t\t , distance = distance\n\t\t }\n\twhere\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tstripParens :: [String] -> [String]\n\t\tstripParens [\"(\":ss]\n\t\t\t| last ss == \")\" && parensMatch 0 (init ss) = stripParens $ init ss\n\t\t\t| otherwise = [\"(\":ss]\n\t\tstripParens ss = ss\n\n\t\tparensMatch :: Int [String] -> Bool\n\t\tparensMatch 0 [] = True\n\t\tparensMatch _ [] = False\n\t\tparensMatch i [\"(\":ss] = i >= 0 && parensMatch (i+1) ss\n\t\tparensMatch i [\")\":ss] = i >= 0 && parensMatch (i-1) ss\n\t\tparensMatch i [_:ss] = i >= 0 && parensMatch i ss\n\n\t\tdistance\n\t\t\t| orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = unify [] orgsearchtype type\n\t\t\t\t= length $ filter (not o isVar o snd) $ ass1 ++ ass2\n\t\t\t# levdist = levenshtein fname orgsearch\n\t\t\t= if (indexOf orgsearch fname == -1) 0 -100 + levdist\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 t2)\n\n\tisNameMatch :: !Int !String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatchF :: ![String] FunctionLocation ExtendedType -> Bool\n\tisModMatchF mods (FL _ mod _) _ = isMember mod mods\n\n\tisModMatchC :: ![String] ClassLocation [TypeVar] FunctionName ExtendedType -> Bool\n\tisModMatchC mods (CL _ mod _) _ _ _ = isMember mod mods\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip +++ \" --> \" +++ toString (length data) +++ \" results (\"\n\t\t\t+++ toString return +++ \"; \" +++ msg +++\n\t\t\tif (isJust more_available) (\"; \" +++ toString (fromJust more_available) +++ \" more\") \"\" +++ \")\\n\"\n\tmsgToString _ _ = \"\"\n\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"508ef66f2170d818c0e33f44f8393bb01d7f2ca1","subject":"Fix basic for ClassResults","message":"Fix basic for ClassResults\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle","old_file":"CloogleServer.icl","new_file":"CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , modules :: Maybe [String]\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(String, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , distance :: Int\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [String]\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , modules = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) +++ \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,modules,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_INVALIDNAME \"function name too long\", w)\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= (err E_INVALIDNAME \"name cannot contain spaces\", w)\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= (err E_INVALIDTYPE \"couldn't parse type\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= flip suggs db)\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !Type !TypeDB -> Maybe [(String, Int)]\n\tsuggs (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t (t`, length $ search {zero & unify=Just t`} db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,modules,page} db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t , isModMatchF <$> modules\n\t\t ]\n\t\t# funs = map (makeFunctionResult name mbType Nothing) $ findFunction`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (CL lib mod _) _ _ f _ -> isNameMatch\n\t\t (size n-2) n (FL lib mod f)) <$> name\n\t\t , isModMatchC <$> modules\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,et)) members\n\t\t\/\/ Search types\n\t\t# lcTypeName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case lcTypeName of\n\t\t\t(Just n) = findType` (\\(TL _ _ t) _ -> toLowerCase t == n) db\n\t\t\tNothing = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td) types\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types\n\n\tmakeClassResult :: (ClassLocation, [TypeVar], ClassContext, [(FunctionName,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult (CL lib mod cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = 0\n\t\t }\n\t\t , { class_name = cls\n\t\t , class_heading = foldl ((+++) o (flip (+++) \" \")) cls vars +++\n\t\t\t if (isEmpty cc) \"\" \" \" +++ concat (print False cc)\n\t\t , class_funs = [f +++ concat (print False t) \\\\ (f,t) <- funs]\n\t\t , class_instances\n\t\t = sort [concat (print False t) \\\\ t <- getInstances cls db]\n\t\t }\n\t\t )\n\n\tmakeTypeResult :: (Maybe String) TypeLocation TypeDef -> Result\n\tmakeTypeResult mbName (TL lib mod t) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t (FunctionLocation, ExtendedType) -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (FL lib mod fname, et=:(ET type tes))\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t }\n\t\t , { func = fname +++ concat (print False et)\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t\t, constructor_of = if (tes.te_isconstructor)\n\t\t\t\t(let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t\t\tNothing\n\t\t }\n\t\t )\n\twhere\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= toInt $ sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)]\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= levenshtein` orgsearch fname\n\t\twhere\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein a b\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) +++ \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatchF :: ![String] FunctionLocation ExtendedType -> Bool\n\tisModMatchF mods (FL _ mod _) _ = isMember mod mods\n\n\tisModMatchC :: ![String] ClassLocation [TypeVar] ClassContext FunctionName ExtendedType -> Bool\n\tisModMatchC mods (CL _ mod _) _ _ _ _ = isMember mod mods\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip +++ \" --> \" +++ toString (length data)\n\t\t\t+++ \" results (\" +++ toString return +++ \"; \" +++ msg +++\n\t\t\tif (isJust more_available) (\"; \" +++ toString (fromJust more_available) +++ \" more\") \"\" +++ \")\\n\"\n\tmsgToString _ _ = \"\"\n","old_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , modules :: Maybe [String]\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(String, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , distance :: Int\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [String]\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , modules = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) +++ \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,modules,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_INVALIDNAME \"function name too long\", w)\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= (err E_INVALIDNAME \"name cannot contain spaces\", w)\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= (err E_INVALIDTYPE \"couldn't parse type\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= flip suggs db)\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !Type !TypeDB -> Maybe [(String, Int)]\n\tsuggs (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t (t`, length $ search {zero & unify=Just t`} db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,modules,page} db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t , isModMatchF <$> modules\n\t\t ]\n\t\t# funs = map (makeFunctionResult name mbType Nothing) $ findFunction`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (CL lib mod _) _ _ f _ -> isNameMatch\n\t\t (size n-2) n (FL lib mod f)) <$> name\n\t\t , isModMatchC <$> modules\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,et)) members\n\t\t\/\/ Search types\n\t\t# lcTypeName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case lcTypeName of\n\t\t\t(Just n) = findType` (\\(TL _ _ t) _ -> toLowerCase t == n) db\n\t\t\tNothing = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td) types\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types\n\n\tmakeClassResult :: (ClassLocation, [TypeVar], ClassContext, [(FunctionName,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult (CL lib mod cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = 0\n\t\t }\n\t\t , { class_name = cls\n\t\t , class_heading = foldl ((+++) o (flip (+++) \" \")) cls vars +++\n\t\t\t if (isEmpty cc) \"\" \" \" +++ concat (print False cc)\n\t\t , class_funs = [f +++ concat (print False t) \\\\ (f,t) <- funs]\n\t\t , class_instances\n\t\t = sort [concat (print False t) \\\\ t <- getInstances cls db]\n\t\t }\n\t\t )\n\n\tmakeTypeResult :: (Maybe String) TypeLocation TypeDef -> Result\n\tmakeTypeResult mbName (TL lib mod t) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t (FunctionLocation, ExtendedType) -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (FL lib mod fname, et=:(ET type tes))\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t }\n\t\t , { func = fname +++ concat (print False et)\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t\t, constructor_of = if (tes.te_isconstructor)\n\t\t\t\t(let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t\t\tNothing\n\t\t }\n\t\t )\n\twhere\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= toInt $ sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)]\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= levenshtein` orgsearch fname\n\t\twhere\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein a b\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) +++ \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatchF :: ![String] FunctionLocation ExtendedType -> Bool\n\tisModMatchF mods (FL _ mod _) _ = isMember mod mods\n\n\tisModMatchC :: ![String] ClassLocation [TypeVar] ClassContext FunctionName ExtendedType -> Bool\n\tisModMatchC mods (CL _ mod _) _ _ _ _ = isMember mod mods\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip +++ \" --> \" +++ toString (length data)\n\t\t\t+++ \" results (\" +++ toString return +++ \"; \" +++ msg +++\n\t\t\tif (isJust more_available) (\"; \" +++ toString (fromJust more_available) +++ \" more\") \"\" +++ \")\\n\"\n\tmsgToString _ _ = \"\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"708f2d439b306fe546e86e1a5a65c4081a1a2677","subject":"Add CTCP ping","message":"Add CTCP ping\n","repos":"clean-cloogle\/clean-irc","old_file":"cloogleirc.icl","new_file":"cloogleirc.icl","new_contents":"module cloogleirc\n\nimport Cloogle\nimport GenPrint\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nimport Data.Either\nfrom Data.Func import $, mapSt\nfrom Text import class Text(..), instance Text String, instance + String\n\nimport Internet.HTTP\n\nimport Text.JSON\n\nimport Text.URI\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad, instance Monad Maybe, >>=\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport System.CommandLine\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\nimport IRC\nimport IRCBot\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# s = if (startsWith \"http:\/\/\" s) s (if (startsWith \"https:\/\/\" s) s (\"http:\/\/\" + s))\n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doHTTPRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} 10000 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\ncloogle :: String *World -> (String, *World)\ncloogle data w\n# (mer, w) = doHTTPRequestL\n\t\t{ newHTTPRequest\n\t\t& req_path = \"\/api.php\"\n\t\t, req_query = \"?str=\" + urlEncode data\n\t\t, req_headers = 'DM'.fromList [(\"User-Agent\", \"cloogle-irc\")]\n\t\t, server_name = \"cloogle.org\"\n\t\t, server_port = 80} 10000 10 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= case fromJSON $ fromString resp.HTTPResponse.rsp_data of\n\tNothing = (\"couldn't parse json\", w)\n\tJust clr = (\"Results for \" + data + \" -- https:\/\/cloogle.org\/#\" +\n\t\treplaceSubString \"+\" \"%20\" (urlEncode data) + \"\\n\" +\n\t\tprocessResults clr, w)\n\twhere\n\t\tprocessResults :: Response -> String\n\t\tprocessResults resp\n\t\t| resp.return > 127 = \"Failed: return code: \" + toString resp.return + \", \" + resp.msg\n\t\t= join \"\\n\" $ map processResult $ take 3 resp.data\n\t\t\n\t\tprocessResult :: Result -> String\n\t\tprocessResult (FunctionResult (br, {func}))\n\t\t\t= \"Function in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ func\n\t\tprocessResult (TypeResult (br, {type}))\n\t\t\t= \"Type in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ limitResults type\n\t\tprocessResult (ClassResult (br, {class_name,class_funs}))\n\t\t\t= \"Class in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ class_name +++ \" with \"\n\t\t\t\t+++ toString (length class_funs) +++ \" class functions\"\n\t\tprocessResult (ModuleResult (br, _))\n\t\t\t= \"Module in \" +++ br.library +++ \": \" +++ br.modul\n\n\t\tlimitResults :: String -> String\n\t\tlimitResults s\n\t\t# lines = split \"\\n\" s\n\t\t| length lines > 4 = limitResults (join \"\\n\" (take 3 lines) + \"\\n...\")\n\t\t= join \"\\n\" (map maxWidth lines)\n\t\t\n\t\tmaxWidth :: String -> String\n\t\tmaxWidth s\n\t\t| size s > 80 = subString 0 77 s + \"...\"\n\t\t= s\n\n:: BotSettings =\n\t\t{ bs_nick :: String\n\t\t, bs_nickserv :: Maybe String\n\t\t, bs_autojoin :: [String]\n\t\t, bs_port :: Int\n\t\t, bs_server :: String\n\t\t}\n\nStart :: *World -> (MaybeErrorString (), *World)\nStart w\n# ([arg0:args], w) = getCommandLine w\n# bs = parseCLI args \n| isError bs = (Error $ \"\\n\" +++ fromError bs +++ \"\\n\", w)\n# (Ok bs) = bs\n= bot (bs.bs_server, bs.bs_port) (startup bs) shutdown () process w\n\twhere\n\t\tparseCLI :: [String] -> MaybeErrorString BotSettings\n\t\tparseCLI [] = Ok\n\t\t\t{ bs_nick = \"clooglebot\"\n\t\t\t, bs_nickserv = Nothing\n\t\t\t, bs_autojoin = []\n\t\t\t, bs_port = 6667\n\t\t\t, bs_server = \"irc.freenode.net\"\n\t\t\t}\n\t\tparseCLI [a:as]\n\t\t| a == \"-n\" || a == \"--nick\"\n\t\t\t= arg1 \"--nick\" as \\a c->{c & bs_nick=a}\n\t\t| a == \"-ns\" || a == \"--nickserv\"\n\t\t\t= arg1 \"--nickserv\" as \\a c->{c & bs_nickserv=Just a}\n\t\t| a == \"-a\" || a == \"--autojoin\"\n\t\t\t= arg1 \"--autojoin\" as \\a c->{c & bs_autojoin=c.bs_autojoin ++ [a]}\n\t\t| a == \"-p\" || a == \"--port\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_port=toInt a}\n\t\t| a == \"-s\" || a == \"--server\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_server=a}\n\t\t| a == \"-h\" || a == \"--help\" = Error $ join \"\\n\" $\n\t\t\t[ \"Usage: cloogle [OPTS]\"\n\t\t\t, \"Options:\"\n\t\t\t, \"\\t--nick\/-n NICKNAME Use the given nickname instead of clooglebot\"\n\t\t\t, \"\\t--nickserv\/-ns PW Identify via the given password with NickServ\"\n\t\t\t, \"\\t--port\/-p PORT Use the given port instead of port 6667\"\n\t\t\t, \"\\t--server\/-s SERVER Use the given server instead of irc.freenode.net\"\n\t\t\t, \"\\t--autojoin\/-a CHANNEL Add CHANNEL to the autojoin list. This command \"\n\t\t\t, \"\\t can be called multiple times. Beware that #\"\n\t\t\t, \"\\t has to be escaped in most shells\"\n\t\t\t]\n\t\t= Error $ \"Unknown option: \" +++ a\n\n\t\targ1 name [] _ = Error $ name +++ \" requires an argument\"\n\t\targ1 name [a:as] f = parseCLI as >>= Ok o f a\n\n\t\tnickserv pw = PRIVMSG (CSepList [\"NickServ\"]) $ \"IDENTIFY \" +++ pw\n\n\t\ttoPrefix c = {irc_prefix=Nothing,irc_command=Right c}\n\n\t\tstartup bs = map toPrefix $\n\t\t\t[ NICK bs.bs_nick Nothing\n\t\t\t, USER \"cloogle\" \"cloogle\" \"cloogle\" \"Cloogle bot\"\n\t\t\t]++ maybe [] (pure o nickserv) bs.bs_nickserv\n\t\t\t ++ if (isEmpty bs.bs_autojoin) []\n\t\t\t\t[JOIN (CSepList bs.bs_autojoin) Nothing]\n\t\tshutdown = map toPrefix [QUIT $ Just \"Bye\"]\n\n\t\tprocess :: IRCMessage () *World -> (Maybe [IRCMessage], (), *World)\n\t\tprocess im s w = case im.irc_command of\n\t\t\tLeft numr = (Just [], (), w)\n\t\t\tRight cmd = case process` im.irc_prefix cmd w of\n\t\t\t\t(Nothing, w) = (Nothing, (), w)\n\t\t\t\t(Just cs, w) = (Just $ map toPrefix cs, (), w)\n\n\t\tprocess` :: (Maybe (Either IRCUser String)) IRCCommand *World -> (Maybe [IRCCommand], *World)\n\t\tprocess` (Just (Left user)) (PRIVMSG t m) w\n\t\t\t| m == \"!restart\" = (Nothing, w)\n\t\t\t| m.[0] == '!'\n\t\t\t\t# (msgs, w) = realProcess (split \" \" $ m % (1, size m)) w\n\t\t\t\t= (Just $ map reply msgs, w)\n\t\t\t| m % (0,4) == \"\\001PING\" = (Just [reply m], w)\n\t\t\t= (Just [], w)\n\t\twhere\n\t\t\treply = case (\\(CSepList [t:_]) -> t.[0]) t of\n\t\t\t\t'#' -> PRIVMSG t\n\t\t\t\t_ -> NOTICE user.irc_nick\n\t\tprocess` _ (PING t mt) w = (Just [PONG t mt], w)\n\t\tprocess` _ _ w = (Just [], w)\n\n\t\trealProcess :: [String] *World -> ([String], *World)\n\t\trealProcess [\"help\",x:xs] w = ((case x of\n\t\t\t\"help\" =\n\t\t\t\t[ \"Usage: !help [ARG]\"\n\t\t\t\t, \"Show this help, or the specific help of the argument\"]\n\t\t\t\"ping\" =\n\t\t\t\t[ \"Usage: !ping [ARG [ARG ...]]\"\n\t\t\t\t, \"Ping the bot, it will pong the arguments back\"]\n\t\t\t\"shorten\" =\n\t\t\t\t[ \"Usage: !shorten URL [URL [URL ...]]\"\n\t\t\t\t, \"Shorten the given urls with the cloo.gl url shortener\"]\n\t\t\t\"query\" =\n\t\t\t\t[ \"Usage: !query QUERY\"\n\t\t\t\t, \"Query QUERY in cloogle and return the results\"]\n\t\t\t\"restart\" =\n\t\t\t\t[ \"Usage: !restart\"\n\t\t\t\t, \"Restart the bot\"]\n\t\t\tx = [\"Unknown command: \" +++ x]\n\t\t\t), w)\n\t\trealProcess [\"help\"] w = (\n\t\t\t[\"Type !help cmd for command specific help\"\n\t\t\t,\"available commands: help, ping, shorten, query, restart\"], w)\n\t\trealProcess [\"ping\":xs] w = ([\"pong \" +++ join \" \" xs], w)\n\t\trealProcess [\"shorten\":xs] w = case xs of\n\t\t\t[] = ([\"shorten requires at least one argument\"], w)\n\t\t\txs = mapSt shorten xs w\n\t\trealProcess [\"query\":xs] w = case xs of\n\t\t\t[] = ([\"query requires one or more arguments\"], w)\n\t\t\txs = appFst (split \"\\n\") $ cloogle (join \" \" xs) w\n\t\trealProcess [\"restart\":_] w = ([\"restart takes no arguments\"], w)\n\t\trealProcess [c:_] w = ([join \" \" [\n\t\t\t\"Unknown cmd: \", c, \", type !help to get help\"]], w)\n","old_contents":"module cloogleirc\n\nimport Cloogle\nimport GenPrint\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nimport Data.Either\nfrom Data.Func import $, mapSt\nfrom Text import class Text(..), instance Text String, instance + String\n\nimport Internet.HTTP\n\nimport Text.JSON\n\nimport Text.URI\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad, instance Monad Maybe, >>=\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport System.CommandLine\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\nimport IRC\nimport IRCBot\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# s = if (startsWith \"http:\/\/\" s) s (if (startsWith \"https:\/\/\" s) s (\"http:\/\/\" + s))\n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doHTTPRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} 10000 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\ncloogle :: String *World -> (String, *World)\ncloogle data w\n# (mer, w) = doHTTPRequestL\n\t\t{ newHTTPRequest\n\t\t& req_path = \"\/api.php\"\n\t\t, req_query = \"?str=\" + urlEncode data\n\t\t, req_headers = 'DM'.fromList [(\"User-Agent\", \"cloogle-irc\")]\n\t\t, server_name = \"cloogle.org\"\n\t\t, server_port = 80} 10000 10 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= case fromJSON $ fromString resp.HTTPResponse.rsp_data of\n\tNothing = (\"couldn't parse json\", w)\n\tJust clr = (\"Results for \" + data + \" -- https:\/\/cloogle.org\/#\" +\n\t\treplaceSubString \"+\" \"%20\" (urlEncode data) + \"\\n\" +\n\t\tprocessResults clr, w)\n\twhere\n\t\tprocessResults :: Response -> String\n\t\tprocessResults resp\n\t\t| resp.return > 127 = \"Failed: return code: \" + toString resp.return + \", \" + resp.msg\n\t\t= join \"\\n\" $ map processResult $ take 3 resp.data\n\t\t\n\t\tprocessResult :: Result -> String\n\t\tprocessResult (FunctionResult (br, {func}))\n\t\t\t= \"Function in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ func\n\t\tprocessResult (TypeResult (br, {type}))\n\t\t\t= \"Type in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ limitResults type\n\t\tprocessResult (ClassResult (br, {class_name,class_funs}))\n\t\t\t= \"Class in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ class_name +++ \" with \"\n\t\t\t\t+++ toString (length class_funs) +++ \" class functions\"\n\t\tprocessResult (ModuleResult (br, _))\n\t\t\t= \"Module in \" +++ br.library +++ \": \" +++ br.modul\n\n\t\tlimitResults :: String -> String\n\t\tlimitResults s\n\t\t# lines = split \"\\n\" s\n\t\t| length lines > 4 = limitResults (join \"\\n\" (take 3 lines) + \"\\n...\")\n\t\t= join \"\\n\" (map maxWidth lines)\n\t\t\n\t\tmaxWidth :: String -> String\n\t\tmaxWidth s\n\t\t| size s > 80 = subString 0 77 s + \"...\"\n\t\t= s\n\n:: BotSettings =\n\t\t{ bs_nick :: String\n\t\t, bs_nickserv :: Maybe String\n\t\t, bs_autojoin :: [String]\n\t\t, bs_port :: Int\n\t\t, bs_server :: String\n\t\t}\n\nStart :: *World -> (MaybeErrorString (), *World)\nStart w\n# ([arg0:args], w) = getCommandLine w\n# bs = parseCLI args \n| isError bs = (Error $ \"\\n\" +++ fromError bs +++ \"\\n\", w)\n# (Ok bs) = bs\n= bot (bs.bs_server, bs.bs_port) (startup bs) shutdown () process w\n\twhere\n\t\tparseCLI :: [String] -> MaybeErrorString BotSettings\n\t\tparseCLI [] = Ok\n\t\t\t{ bs_nick = \"clooglebot\"\n\t\t\t, bs_nickserv = Nothing\n\t\t\t, bs_autojoin = []\n\t\t\t, bs_port = 6667\n\t\t\t, bs_server = \"irc.freenode.net\"\n\t\t\t}\n\t\tparseCLI [a:as]\n\t\t| a == \"-n\" || a == \"--nick\"\n\t\t\t= arg1 \"--nick\" as \\a c->{c & bs_nick=a}\n\t\t| a == \"-ns\" || a == \"--nickserv\"\n\t\t\t= arg1 \"--nickserv\" as \\a c->{c & bs_nickserv=Just a}\n\t\t| a == \"-a\" || a == \"--autojoin\"\n\t\t\t= arg1 \"--autojoin\" as \\a c->{c & bs_autojoin=c.bs_autojoin ++ [a]}\n\t\t| a == \"-p\" || a == \"--port\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_port=toInt a}\n\t\t| a == \"-s\" || a == \"--server\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_server=a}\n\t\t| a == \"-h\" || a == \"--help\" = Error $ join \"\\n\" $\n\t\t\t[ \"Usage: cloogle [OPTS]\"\n\t\t\t, \"Options:\"\n\t\t\t, \"\\t--nick\/-n NICKNAME Use the given nickname instead of clooglebot\"\n\t\t\t, \"\\t--nickserv\/-ns PW Identify via the given password with NickServ\"\n\t\t\t, \"\\t--port\/-p PORT Use the given port instead of port 6667\"\n\t\t\t, \"\\t--server\/-s SERVER Use the given server instead of irc.freenode.net\"\n\t\t\t, \"\\t--autojoin\/-a CHANNEL Add CHANNEL to the autojoin list. This command \"\n\t\t\t, \"\\t can be called multiple times. Beware that #\"\n\t\t\t, \"\\t has to be escaped in most shells\"\n\t\t\t]\n\t\t= Error $ \"Unknown option: \" +++ a\n\n\t\targ1 name [] _ = Error $ name +++ \" requires an argument\"\n\t\targ1 name [a:as] f = parseCLI as >>= Ok o f a\n\n\t\tnickserv pw = PRIVMSG (CSepList [\"NickServ\"]) $ \"IDENTIFY \" +++ pw\n\n\t\ttoPrefix c = {irc_prefix=Nothing,irc_command=Right c}\n\n\t\tstartup bs = map toPrefix $\n\t\t\t[ NICK bs.bs_nick Nothing\n\t\t\t, USER \"cloogle\" \"cloogle\" \"cloogle\" \"Cloogle bot\"\n\t\t\t]++ maybe [] (pure o nickserv) bs.bs_nickserv\n\t\t\t ++ if (isEmpty bs.bs_autojoin) []\n\t\t\t\t[JOIN (CSepList bs.bs_autojoin) Nothing]\n\t\tshutdown = map toPrefix [QUIT $ Just \"Bye\"]\n\n\t\tprocess :: IRCMessage () *World -> (Maybe [IRCMessage], (), *World)\n\t\tprocess im s w = case im.irc_command of\n\t\t\tLeft numr = (Just [], (), w)\n\t\t\tRight cmd = case process` im.irc_prefix cmd w of\n\t\t\t\t(Nothing, w) = (Nothing, (), w)\n\t\t\t\t(Just cs, w) = (Just $ map toPrefix cs, (), w)\n\n\t\tprocess` :: (Maybe (Either IRCUser String)) IRCCommand *World -> (Maybe [IRCCommand], *World)\n\t\tprocess` (Just (Left user)) (PRIVMSG t m) w\n\t\t\t| m == \"!restart\" = (Nothing, w)\n\t\t\t| m.[0] == '!'\n\t\t\t\t# (msgs, w) = realProcess (split \" \" $ m % (1, size m)) w\n\t\t\t\t= (Just $ map reply msgs, w)\n\t\t\t= (Just [], w)\n\t\twhere\n\t\t\treply = case (\\(CSepList [t:_]) -> t.[0]) t of\n\t\t\t\t'#' -> PRIVMSG t\n\t\t\t\t_ -> NOTICE user.irc_nick\n\t\tprocess` _ (PING t mt) w = (Just [PONG t mt], w)\n\t\tprocess` _ _ w = (Just [], w)\n\n\t\trealProcess :: [String] *World -> ([String], *World)\n\t\trealProcess [\"help\",x:xs] w = ((case x of\n\t\t\t\"help\" =\n\t\t\t\t[ \"Usage: !help [ARG]\"\n\t\t\t\t, \"Show this help, or the specific help of the argument\"]\n\t\t\t\"ping\" =\n\t\t\t\t[ \"Usage: !ping [ARG [ARG ...]]\"\n\t\t\t\t, \"Ping the bot, it will pong the arguments back\"]\n\t\t\t\"shorten\" =\n\t\t\t\t[ \"Usage: !shorten URL [URL [URL ...]]\"\n\t\t\t\t, \"Shorten the given urls with the cloo.gl url shortener\"]\n\t\t\t\"query\" =\n\t\t\t\t[ \"Usage: !query QUERY\"\n\t\t\t\t, \"Query QUERY in cloogle and return the results\"]\n\t\t\t\"restart\" =\n\t\t\t\t[ \"Usage: !restart\"\n\t\t\t\t, \"Restart the bot\"]\n\t\t\tx = [\"Unknown command: \" +++ x]\n\t\t\t), w)\n\t\trealProcess [\"help\"] w = (\n\t\t\t[\"Type !help cmd for command specific help\"\n\t\t\t,\"available commands: help, ping, shorten, query, restart\"], w)\n\t\trealProcess [\"ping\":xs] w = ([\"pong \" +++ join \" \" xs], w)\n\t\trealProcess [\"shorten\":xs] w = case xs of\n\t\t\t[] = ([\"shorten requires at least one argument\"], w)\n\t\t\txs = mapSt shorten xs w\n\t\trealProcess [\"query\":xs] w = case xs of\n\t\t\t[] = ([\"query requires one or more arguments\"], w)\n\t\t\txs = appFst (split \"\\n\") $ cloogle (join \" \" xs) w\n\t\trealProcess [\"restart\":_] w = ([\"restart takes no arguments\"], w)\n\t\trealProcess [c:_] w = ([join \" \" [\n\t\t\t\"Unknown cmd: \", c, \", type !help to get help\"]], w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"b7859b73bdf1caac6bf5b54a4a10cd8541ebfd14","subject":"Added modules to builddb statistics","message":"Added modules to builddb statistics\n","repos":"dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/builddb.icl","new_file":"backend\/builddb.icl","new_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, ::Macro{..}, ::ModuleInfo{..},\n\tinstance zero TypeExtras, instance zero ModuleInfo\n\n\/\/ StdEnv\nfrom StdFunc import const, flip, o\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf,startsWith),\n\tinstance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String,\n\tinstance print Type, instance print Priority\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos,td_ident},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"ArgEnv\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"clean-platform\/OS-Independent\", const False)\n\t , (\"clean-platform\/OS-Linux\", const False)\n\t , (\"clean-platform\/OS-Linux-32\", const False)\n\t , (\"clean-platform\/OS-Linux-64\", const False)\n\t , (\"clean-platform\/OS-Mac\", const False)\n\t , (\"clean-platform\/OS-Posix\", const False)\n\t , (\"clean-platform\/OS-Windows\", const False)\n\t , (\"clean-platform\/OS-Windows-32\", const False)\n\t , (\"clean-platform\/OS-Windows-64\", const False)\n\t , (\"iTasks-SDK\/Dependencies\/graph_copy\", const False)\n\t , (\"iTasks-SDK\/Dependencies\/clean-sapl\/src\", const False)\n\t , (\"iTasks-SDK\/Server\", startsWith \"iTasks._Framework\")\n\t , (\"iTasks-SDK\/Tests\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"SoccerFun\/Game\", const False)\n\t , (\"SoccerFun\/Gui\", const False)\n\t , (\"SoccerFun\/StdLibExt\", const False)\n\t , (\"SoccerFun\/StdReferee\", const False)\n\t , (\"SoccerFun\/StdTeam\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"clean-platform\/OS-Independent\/Deprecated\"\n\t , \"iTasks-SDK\/Server\/lib\"\n\t , \"SoccerFun\/StdReferee\/RefereeCoach_\"\n\t , \"SoccerFun\/StdTeam\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putClasses predefClasses db\n\t# db = 'DB'.putTypes predefTypes db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = 'DB'.saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] 'DB'.TypeDB\n\t\t*DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod,iscore):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib iscore cache db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !'DB'.TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ 'DB'.moduleCount db\n\t\t\t\t, 'DB'.functionCount db\n\t\t\t\t, 'DB'.macroCount db\n\t\t\t\t, 'DB'.typeCount db\n\t\t\t\t, 'DB'.classCount db\n\t\t\t\t, 'DB'.instanceCount db\n\t\t\t\t, 'DB'.deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t , ( 'DB'.Builtin \"dynamic\"\n\t , 'DB'.ET ('T'.Func ['T'.Var \"a\"] ('T'.Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext, [('DB'.Name, 'DB'.ExtendedType)])]\npredefClasses\n\t= [ ( 'DB'.Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"_#Array\" ['T'.Type \"Char\" []]) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[], 'Type'.cons_priority=Nothing}\n\n\/\/ Exclude Root Library Check for core Base module\nfindModules :: ![String] !String !'DB'.Library ('DB'.Module -> Bool) !String !*World\n\t-> *(![('DB'.Library, 'DB'.Module, Bool)], !*World)\nfindModules ex root lib iscore base w\n| any (\\e -> indexOf e path <> -1) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s -> let mod = basedot +++ s % (0, size s - 5) in\n\t(lib, mod, iscore mod)) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (\\d -> findModules ex root lib iscore (basedot +++ d)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any (\\e -> indexOf e (path +++ \"\/\" +++ s) <> -1) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String 'DB'.Module 'DB'.Library Bool\n\t*DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib iscore cache db w\n# (Right dcl,cache,w) = readModule False cache w\n# (icl,cache,w) = readModule True cache w\n# icl = case icl of (Left _) = Nothing; (Right x) = Just x\n# mod = dcl.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putFunctions (pd_typespecs lib mod dcl.mod_defs icl) db\n# db = 'DB'.putInstances (pd_instances lib mod dcl.mod_defs icl) db\n# db = 'DB'.putClasses (pd_classes lib mod dcl.mod_defs icl) db\n# typedefs = pd_types lib mod dcl.mod_defs icl\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib mod dcl.mod_defs) db\n# db = 'DB'.putDerivationss (pd_derivations lib mod dcl.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib mod dcl.mod_defs) db\n# db = 'DB'.putModule lib mod {zero & is_core=iscore} db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine pos) Nothing id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= 'T'.toMaybePriority}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- dcl]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id dcl of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id dcl\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):dcl]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:dcl] = findTypeSpec id dcl\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, 'DB'.Location)])]\n\tpd_derivations lib mod dcl\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, 'DB'.Location lib mod (toLine gc_pos) Nothing \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- dcl, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) Nothing id_name\n\t\t , 'DB'.ET ('T'.toType gen_type)\n\t\t {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars\n\t\t , te_representation=Just $ cpp gen}\n\t\t ) \\\\ gen=:(PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars}) <- dcl]\n\n\tpd_typespecs :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType t)\n\t\t { zero & te_priority = 'T'.toMaybePriority p\n\t\t , te_representation = Just $ cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pos \\\\ PD_TypeSpec pos id _ _ _ <- pms | id.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_instances :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Class, ['DB'.Type], 'DB'.Location)]\n\tpd_instances lib mod dcl icl\n\t\t= [( id_name\n\t\t , map 'T'.toType pi_types\n\t\t , 'DB'.Location lib mod (toLine pi_pos) (findIclLine id_name =<< icl) \"\"\n\t\t ) \\\\ PD_Instance {pim_pi={pi_ident={id_name},pi_types,pi_pos}} <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pi_pos \\\\ PD_Instance {pim_pi={pi_pos,pi_ident}} <- pms | pi_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_classes :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod dcl icl\n\t# dcl = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) dcl\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} dcl)\n\t\t-> let typespecs = pd_typespecs lib mod dcl icl\n\t\tin ('DB'.Location lib mod (toLine class_pos) (findIclLine id_name =<< icl) id_name\n\t\t , map 'T'.toTypeVar class_args\n\t\t , flatten $ map 'T'.toClassContext class_context\n\t\t , [(f,et) \\\\ ('DB'.Location _ _ _ _ f, et) <- typespecs])) dcl\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [class_pos \\\\ PD_Class {class_ident,class_pos} _ <- pms | class_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_types :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod dcl icl\n\t\t= [let name = 'T'.td_name td in\n\t\t\t('DB'.Location lib mod (toLine ptd.td_pos) (findIclLine name =<< icl) name, td)\n\t\t \\\\ PD_Type ptd <- dcl, td <- ['T'.toTypeDef ptd]]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [td_pos \\\\ PD_Type {td_ident,td_pos} <- pms | td_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tconstructor_functions ('DB'.Location lib mod line iclline _, td)\n\t\t= [('DB'.Location lib mod line iclline c, 'DB'.ET f\n\t\t\t{zero & te_isconstructor=True\n\t\t\t , te_representation=Just $ concat $\n\t\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t\t , te_priority=p})\n\t\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\n\twhere\n\t\tprint_prio :: (Maybe 'T'.Priority) -> [String]\n\t\tprint_prio Nothing = []\n\t\tprint_prio (Just p) = [\" \"] ++ print False p\n\n\trecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\trecord_functions ('DB'.Location lib mod line iclline _, td)\n\t\t= [('DB'.Location lib mod line iclline f, 'DB'.ET t\n\t\t\t{zero & te_isrecordfield=True\n\t\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\n\treadModule :: Bool *DclCache *World -> *(Either String ParsedModule, *DclCache, *World)\n\treadModule icl cache w\n\t# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ if icl \".icl\" \".dcl\"\n\t# (ok,f,w) = fopen filename FReadText w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n\t cache = {cache & hash_table=ht}\n\t# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" icl mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n\t cache = {cache & hash_table=ht}\n\t# (ok,w) = fclose f w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t= (Right pm, cache, w)\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","old_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, ::Macro{..}, ::ModuleInfo{..},\n\tinstance zero TypeExtras, instance zero ModuleInfo\n\n\/\/ StdEnv\nfrom StdFunc import const, flip, o\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf,startsWith),\n\tinstance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String,\n\tinstance print Type, instance print Priority\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos,td_ident},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"ArgEnv\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"clean-platform\/OS-Independent\", const False)\n\t , (\"clean-platform\/OS-Linux\", const False)\n\t , (\"clean-platform\/OS-Linux-32\", const False)\n\t , (\"clean-platform\/OS-Linux-64\", const False)\n\t , (\"clean-platform\/OS-Mac\", const False)\n\t , (\"clean-platform\/OS-Posix\", const False)\n\t , (\"clean-platform\/OS-Windows\", const False)\n\t , (\"clean-platform\/OS-Windows-32\", const False)\n\t , (\"clean-platform\/OS-Windows-64\", const False)\n\t , (\"iTasks-SDK\/Dependencies\/graph_copy\", const False)\n\t , (\"iTasks-SDK\/Dependencies\/clean-sapl\/src\", const False)\n\t , (\"iTasks-SDK\/Server\", startsWith \"iTasks._Framework\")\n\t , (\"iTasks-SDK\/Tests\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"SoccerFun\/Game\", const False)\n\t , (\"SoccerFun\/Gui\", const False)\n\t , (\"SoccerFun\/StdLibExt\", const False)\n\t , (\"SoccerFun\/StdReferee\", const False)\n\t , (\"SoccerFun\/StdTeam\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"clean-platform\/OS-Independent\/Deprecated\"\n\t , \"iTasks-SDK\/Server\/lib\"\n\t , \"SoccerFun\/StdReferee\/RefereeCoach_\"\n\t , \"SoccerFun\/StdTeam\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putClasses predefClasses db\n\t# db = 'DB'.putTypes predefTypes db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = 'DB'.saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] 'DB'.TypeDB\n\t\t*DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod,iscore):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib iscore cache db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !'DB'.TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ 'DB'.functionCount db\n\t\t\t\t, 'DB'.macroCount db\n\t\t\t\t, 'DB'.typeCount db\n\t\t\t\t, 'DB'.classCount db\n\t\t\t\t, 'DB'.instanceCount db\n\t\t\t\t, 'DB'.deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t , ( 'DB'.Builtin \"dynamic\"\n\t , 'DB'.ET ('T'.Func ['T'.Var \"a\"] ('T'.Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext, [('DB'.Name, 'DB'.ExtendedType)])]\npredefClasses\n\t= [ ( 'DB'.Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"_#Array\" ['T'.Type \"Char\" []]) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[], 'Type'.cons_priority=Nothing}\n\n\/\/ Exclude Root Library Check for core Base module\nfindModules :: ![String] !String !'DB'.Library ('DB'.Module -> Bool) !String !*World\n\t-> *(![('DB'.Library, 'DB'.Module, Bool)], !*World)\nfindModules ex root lib iscore base w\n| any (\\e -> indexOf e path <> -1) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s -> let mod = basedot +++ s % (0, size s - 5) in\n\t(lib, mod, iscore mod)) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (\\d -> findModules ex root lib iscore (basedot +++ d)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any (\\e -> indexOf e (path +++ \"\/\" +++ s) <> -1) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String 'DB'.Module 'DB'.Library Bool\n\t*DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib iscore cache db w\n# (Right dcl,cache,w) = readModule False cache w\n# (icl,cache,w) = readModule True cache w\n# icl = case icl of (Left _) = Nothing; (Right x) = Just x\n# mod = dcl.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putFunctions (pd_typespecs lib mod dcl.mod_defs icl) db\n# db = 'DB'.putInstances (pd_instances lib mod dcl.mod_defs icl) db\n# db = 'DB'.putClasses (pd_classes lib mod dcl.mod_defs icl) db\n# typedefs = pd_types lib mod dcl.mod_defs icl\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib mod dcl.mod_defs) db\n# db = 'DB'.putDerivationss (pd_derivations lib mod dcl.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib mod dcl.mod_defs) db\n# db = 'DB'.putModule lib mod {zero & is_core=iscore} db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine pos) Nothing id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= 'T'.toMaybePriority}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- dcl]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id dcl of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id dcl\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):dcl]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:dcl] = findTypeSpec id dcl\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, 'DB'.Location)])]\n\tpd_derivations lib mod dcl\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, 'DB'.Location lib mod (toLine gc_pos) Nothing \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- dcl, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) Nothing id_name\n\t\t , 'DB'.ET ('T'.toType gen_type)\n\t\t {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars\n\t\t , te_representation=Just $ cpp gen}\n\t\t ) \\\\ gen=:(PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars}) <- dcl]\n\n\tpd_typespecs :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType t)\n\t\t { zero & te_priority = 'T'.toMaybePriority p\n\t\t , te_representation = Just $ cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pos \\\\ PD_TypeSpec pos id _ _ _ <- pms | id.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_instances :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Class, ['DB'.Type], 'DB'.Location)]\n\tpd_instances lib mod dcl icl\n\t\t= [( id_name\n\t\t , map 'T'.toType pi_types\n\t\t , 'DB'.Location lib mod (toLine pi_pos) (findIclLine id_name =<< icl) \"\"\n\t\t ) \\\\ PD_Instance {pim_pi={pi_ident={id_name},pi_types,pi_pos}} <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pi_pos \\\\ PD_Instance {pim_pi={pi_pos,pi_ident}} <- pms | pi_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_classes :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod dcl icl\n\t# dcl = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) dcl\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} dcl)\n\t\t-> let typespecs = pd_typespecs lib mod dcl icl\n\t\tin ('DB'.Location lib mod (toLine class_pos) (findIclLine id_name =<< icl) id_name\n\t\t , map 'T'.toTypeVar class_args\n\t\t , flatten $ map 'T'.toClassContext class_context\n\t\t , [(f,et) \\\\ ('DB'.Location _ _ _ _ f, et) <- typespecs])) dcl\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [class_pos \\\\ PD_Class {class_ident,class_pos} _ <- pms | class_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_types :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod dcl icl\n\t\t= [let name = 'T'.td_name td in\n\t\t\t('DB'.Location lib mod (toLine ptd.td_pos) (findIclLine name =<< icl) name, td)\n\t\t \\\\ PD_Type ptd <- dcl, td <- ['T'.toTypeDef ptd]]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [td_pos \\\\ PD_Type {td_ident,td_pos} <- pms | td_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tconstructor_functions ('DB'.Location lib mod line iclline _, td)\n\t\t= [('DB'.Location lib mod line iclline c, 'DB'.ET f\n\t\t\t{zero & te_isconstructor=True\n\t\t\t , te_representation=Just $ concat $\n\t\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t\t , te_priority=p})\n\t\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\n\twhere\n\t\tprint_prio :: (Maybe 'T'.Priority) -> [String]\n\t\tprint_prio Nothing = []\n\t\tprint_prio (Just p) = [\" \"] ++ print False p\n\n\trecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\trecord_functions ('DB'.Location lib mod line iclline _, td)\n\t\t= [('DB'.Location lib mod line iclline f, 'DB'.ET t\n\t\t\t{zero & te_isrecordfield=True\n\t\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\n\treadModule :: Bool *DclCache *World -> *(Either String ParsedModule, *DclCache, *World)\n\treadModule icl cache w\n\t# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ if icl \".icl\" \".dcl\"\n\t# (ok,f,w) = fopen filename FReadText w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n\t cache = {cache & hash_table=ht}\n\t# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" icl mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n\t cache = {cache & hash_table=ht}\n\t# (ok,w) = fclose f w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t= (Right pm, cache, w)\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"1cda166c1d4c6fc31a41aadd1e226ded7533962c","subject":"Add --module-filter and --exclude-builtins to builddb","message":"Add --module-filter and --exclude-builtins to builddb\n","repos":"dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/builddb.icl","new_file":"backend\/builddb.icl","new_contents":"module builddb\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import const, flip, id, o\nimport StdList\nimport StdMisc\nimport StdString\nimport StdTuple\n\nimport Clean.Types\nimport Control.Monad => qualified join\nimport Data.Either\nimport Data.Error\nfrom Data.Func import $, hyperstrict, mapSt\nimport Data.Functor\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport System.File\nimport System.Options\nfrom Text import class Text(join,startsWith), instance Text String\nimport Text.GenJSON\n\nimport Regex.Match\nimport Regex.Parse\n\nimport Cloogle.DB\nfrom Cloogle.DB.Factory import :: TemporaryDB, newTemporaryDB, finaliseDB,\n\tfindModules, indexModule, constructor_functions, record_functions,\n\t:: IndexItem, :: SourceURL, :: PathPattern\n\nimport Builtin.ABC\nimport Builtin.Predef\nimport Builtin.Syntax\n\n:: Options =\n\t{ root :: !String\n\t, libs_file :: !String\n\t, module_filter :: !Maybe Regex\n\t, include_builtins :: !Bool\n\t}\n\nderive JSONDecode IndexItem, SourceURL, PathPattern\n\ninstance zero Options\nwhere\n\tzero =\n\t\t{ root = \"\/opt\/clean\/lib\/\"\n\t\t, libs_file = \"libs.json\"\n\t\t, module_filter = Nothing\n\t\t, include_builtins = True\n\t\t}\n\noptionDescription :: Option Options\noptionDescription = WithHelp True $ Options\n\t[ Shorthand \"-r\" \"--root\" $ Option\n\t\t\"--root\"\n\t\t(\\dir opts -> Ok {opts & root=dir})\n\t\t\"PATH\"\n\t\t\"Use PATH as the root directory for libraries (default: \/opt\/clean\/lib)\"\n\t, Shorthand \"-l\" \"--libraries\" $ Option\n\t\t\"--libraries\"\n\t\t(\\file opts -> Ok {opts & libs_file=file})\n\t\t\"FILE\"\n\t\t\"Use FILE for a list of libraries to index (default: libs.json)\"\n\t, Option\n\t\t\"--module-filter\"\n\t\t(\\filter opts -> case compile filter of\n\t\t\tError e -> Error [\"Regex parsing failed: \" +++ e]\n\t\t\tOk rgx -> Ok {opts & module_filter=Just rgx})\n\t\t\"REGEX\"\n\t\t\"Only index modules matching the regular expression REGEX\"\n\t, Flag\n\t\t\"--exclude-builtins\"\n\t\t(\\opts -> Ok {opts & include_builtins=False})\n\t\t\"Exclude builtins from the index\"\n\t]\n\nStart :: *World -> *World\nStart w\n# ([prog:args], w) = getCommandLine w\n# opts = parseOptions optionDescription args zero\n| isError opts\n\t# err = stderr <<< join \"\\n\" (fromError opts) <<< \"\\n\"\n\t# (_,w) = fclose err w\n\t= w\n# opts = fromOk opts\n# (libsf, w) = readFile opts.libs_file w\n# libsjson = fromString $ fromOk libsf\n# libs = case libsjson of\n\tJSONObject groups -> sequence $ [fromJSON i \\\\ (_,JSONArray g) <- groups, i <- g]\n\t_ -> Nothing\n| isError libsf || isNothing libs\n\t# err = stderr <<< \"Could not read \" <<< opts.libs_file <<< \"\\n\"\n\t# (_,w) = fclose err w\n\t= w\n# libs = fromJust libs\n# (mods, w) = mapSt (flip (findModules opts.root) \"\") libs w\n# mods = flatten mods\n# mods = case opts.module_filter of\n\tJust ftr -> filter (\\m -> not $ isEmpty $ match ftr $ fromString $ getName m.me_loc) mods\n\tNothing -> mods\n#! (db, w) = loop opts.root mods newTemporaryDB w\n#! (ok,w) = fclose (stderr <<< \"Linking database entries; this may take up to 10 minutes...\\n\") w\n| not ok = abort \"Couldn't close stderr\\n\"\n#! db = finaliseDB (if opts.include_builtins builtins []) db\n#! (db,err) = printStats db stderr\n#! (ok1,w) = fclose err w\n#! (f, w) = stdio w\n#! (db,f) = saveDB db f\n#! (ok2,w) = fclose f w\n#! (_,dbg,w) = fopen \"typetree.dot\" FWriteText w\n#! (db,dbg) = writeTypeTree db dbg\n#! (_,w) = fclose dbg w\n= w\nwhere\n\tloop :: String [ModuleEntry] !TemporaryDB !*World -> *(!TemporaryDB, !*World)\n\tloop _ [] db w = (db,w)\n\tloop root [mod:list] db w\n\t#! (_, w) = fclose (stderr <<< lib <<< \": \" <<< modname <<< \"\\n\") w\n\t#! (db, w) = indexModule False root mod db w\n\t#! db = hyperstrict db\n\t= loop root list db w\n\twhere\n\t\tlib = fromJust (getLibrary mod.me_loc)\n\t\tmodname = getName mod.me_loc\n\n\tbuiltins =\n\t\tmap FunctionEntry builtin_functions ++\n\t\tmap ClassEntry builtin_classes ++\n\t\tmap TypeDefEntry builtin_types ++\n\t\tmap FunctionEntry (concatMap constructor_functions builtin_types) ++\n\t\tmap FunctionEntry (concatMap record_functions builtin_types) ++\n\t\tmap SyntaxEntry builtin_syntax ++\n\t\tmap ABCInstructionEntry builtin_abc_instructions\n\n\tprintStats :: !*CloogleDB !*File -> *(*CloogleDB, *File)\n\tprintStats db f\n\t# (s,db) = dbStats db\n\t= (db, f\n\t\t<<< \"| Table | Size |\\n\"\n\t\t<<< \"|-------------------|------:|\\n\"\n\t\t<< \"Modules\" <-- s.n_modules\n\t\t<< \"Functions\" <-- s.n_functions\n\t\t<< \"With types\" <-- s.n_functions_with_type\n\t\t<< \"Unique types\" <-- s.n_unique_types\n\t\t<< \"Type tree depth\" <-- s.type_tree_depth\n\t\t<< \"Type definitions\" <-- s.n_type_definitions\n\t\t<< \"Classes\" <-- s.n_classes\n\t\t<< \"Instances\" <-- s.n_instances\n\t\t<< \"Derivations\" <-- s.n_derivations\n\t\t<< \"Syntax constructs\" <-- s.n_syntax_constructs\n\t\t<< \"ABC instructions\" <-- s.n_abc_instructions)\n\twhere\n\t\t(<<) infixl :: *File String -> *File\n\t\t(<<) f s = f <<< \"| \" <<< rpad 17 s <<< \" | \"\n\n\t\t(<--) infixl :: *File Int -> *File\n\t\t(<--) f i = f <<< lpad 5 i <<< \" |\\n\"\n\n\t\tlpad n s = {' ' \\\\ _ <- [0..n-size (toString s)-1]} +++ toString s\n\t\trpad n s = toString s +++ {' ' \\\\ _ <- [0..n-size (toString s)-1]}\n","old_contents":"module builddb\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import const, flip, id, o\nimport StdList\nimport StdMisc\nimport StdString\nimport StdTuple\n\nimport Clean.Types\nimport Control.Monad => qualified join\nimport Data.Either\nimport Data.Error\nfrom Data.Func import $, hyperstrict, mapSt\nimport Data.Functor\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport System.File\nimport System.Options\nfrom Text import class Text(join,startsWith), instance Text String\nimport Text.GenJSON\n\nimport Cloogle.DB\nfrom Cloogle.DB.Factory import :: TemporaryDB, newTemporaryDB, finaliseDB,\n\tfindModules, indexModule, constructor_functions, record_functions,\n\t:: IndexItem, :: SourceURL, :: PathPattern\n\nimport Builtin.ABC\nimport Builtin.Predef\nimport Builtin.Syntax\n\n:: Options =\n\t{ root :: !String\n\t, libs_file :: !String\n\t}\n\nderive JSONDecode IndexItem, SourceURL, PathPattern\n\ninstance zero Options\nwhere\n\tzero =\n\t\t{ root = \"\/opt\/clean\/lib\/\"\n\t\t, libs_file = \"libs.json\"\n\t\t}\n\noptionDescription :: Option Options\noptionDescription = WithHelp True $ Options\n\t[ Shorthand \"-r\" \"--root\" $ Option\n\t\t\"--root\"\n\t\t(\\dir opts -> Ok {opts & root=dir})\n\t\t\"PATH\"\n\t\t\"Use PATH as the root directory for libraries (default: \/opt\/clean\/lib)\"\n\t, Shorthand \"-l\" \"--libraries\" $ Option\n\t\t\"--libraries\"\n\t\t(\\file opts -> Ok {opts & libs_file=file})\n\t\t\"FILE\"\n\t\t\"Use FILE for a list of libraries to index (default: libs.json)\"\n\t]\n\nStart :: *World -> *World\nStart w\n# (f, w) = stdio w\n# ([prog:args], w) = getCommandLine w\n# opts = parseOptions optionDescription args zero\n| isError opts\n\t# f = f <<< join \"\\n\" (fromError opts) <<< \"\\n\"\n\t# (_,w) = fclose f w\n\t= w\n# opts = fromOk opts\n# (libsf, w) = readFile opts.libs_file w\n# libsjson = fromString $ fromOk libsf\n# libs = case libsjson of\n\tJSONObject groups -> sequence $ [fromJSON i \\\\ (_,JSONArray g) <- groups, i <- g]\n\t_ -> Nothing\n| isError libsf || isNothing libs\n\t# err = stderr <<< \"Could not read \" <<< opts.libs_file <<< \"\\n\"\n\t# (_,w) = fclose err w\n\t# (_,w) = fclose f w\n\t= w\n# libs = fromJust libs\n# (mods, w) = mapSt (flip (findModules opts.root) \"\") libs w\n# mods = flatten mods\n#! (db, w) = loop opts.root mods newTemporaryDB w\n#! (ok,w) = fclose (stderr <<< \"Linking database entries; this may take up to 10 minutes...\\n\") w\n| not ok = abort \"Couldn't close stderr\\n\"\n#! db = finaliseDB builtins db\n#! (db,err) = printStats db stderr\n#! (ok1,w) = fclose err w\n#! (db,f) = saveDB db f\n#! (ok2,w) = fclose f w\n#! (_,dbg,w) = fopen \"typetree.dot\" FWriteText w\n#! (db,dbg) = writeTypeTree db dbg\n#! (_,w) = fclose dbg w\n= w\nwhere\n\tloop :: String [ModuleEntry] !TemporaryDB !*World -> *(!TemporaryDB, !*World)\n\tloop _ [] db w = (db,w)\n\tloop root [mod:list] db w\n\t#! (_, w) = fclose (stderr <<< lib <<< \": \" <<< modname <<< \"\\n\") w\n\t#! (db, w) = indexModule False root mod db w\n\t#! db = hyperstrict db\n\t= loop root list db w\n\twhere\n\t\tlib = fromJust (getLibrary mod.me_loc)\n\t\tmodname = getName mod.me_loc\n\n\tbuiltins =\n\t\tmap FunctionEntry builtin_functions ++\n\t\tmap ClassEntry builtin_classes ++\n\t\tmap TypeDefEntry builtin_types ++\n\t\tmap FunctionEntry (concatMap constructor_functions builtin_types) ++\n\t\tmap FunctionEntry (concatMap record_functions builtin_types) ++\n\t\tmap SyntaxEntry builtin_syntax ++\n\t\tmap ABCInstructionEntry builtin_abc_instructions\n\n\tprintStats :: !*CloogleDB !*File -> *(*CloogleDB, *File)\n\tprintStats db f\n\t# (s,db) = dbStats db\n\t= (db, f\n\t\t<<< \"| Table | Size |\\n\"\n\t\t<<< \"|-------------------|------:|\\n\"\n\t\t<< \"Modules\" <-- s.n_modules\n\t\t<< \"Functions\" <-- s.n_functions\n\t\t<< \"With types\" <-- s.n_functions_with_type\n\t\t<< \"Unique types\" <-- s.n_unique_types\n\t\t<< \"Type tree depth\" <-- s.type_tree_depth\n\t\t<< \"Type definitions\" <-- s.n_type_definitions\n\t\t<< \"Classes\" <-- s.n_classes\n\t\t<< \"Instances\" <-- s.n_instances\n\t\t<< \"Derivations\" <-- s.n_derivations\n\t\t<< \"Syntax constructs\" <-- s.n_syntax_constructs\n\t\t<< \"ABC instructions\" <-- s.n_abc_instructions)\n\twhere\n\t\t(<<) infixl :: *File String -> *File\n\t\t(<<) f s = f <<< \"| \" <<< rpad 17 s <<< \" | \"\n\n\t\t(<--) infixl :: *File Int -> *File\n\t\t(<--) f i = f <<< lpad 5 i <<< \" |\\n\"\n\n\t\tlpad n s = {' ' \\\\ _ <- [0..n-size (toString s)-1]} +++ toString s\n\t\trpad n s = toString s +++ {' ' \\\\ _ <- [0..n-size (toString s)-1]}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"1fcfd33230c60d3d34a03df2f043567027a5006c","subject":"Add array comprehension to builtin syntax","message":"Add array comprehension to builtin syntax\n\nThis resolves some tasks from #180.\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \".\", \"%:\", \"[*<=*]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i\\\\i<-[0,2..9] } \/\/ Fancy things can be done if you combine this with a {{ZF}}. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code =\n\t\t[\"[... \\\\\\\\ ... <- ...]\"\n\t\t,\"{... \\\\\\\\ ... <- ...}\"]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \".\", \"%:\", \"[*<=*]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i\\\\i<-[0,2..9] } \/\/ Fancy things can be done if you combine this with a {{ZF}}. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"6e3aa18950d1897604143661f1c626f505843867","subject":"Typos","message":"Typos\n\ngit-svn-id: 152f48a1866dc7886cc2b83d2001e6645df26423@1004862 13f79535-47bb-0310-9956-ffa450edef68\n","repos":"sgoeschl\/commons-exec,mohanaraosv\/commons-exec,apache\/commons-exec,sgoeschl\/commons-exec,apache\/commons-exec,mohanaraosv\/commons-exec","old_file":"src\/test\/scripts\/ping.dcl","new_file":"src\/test\/scripts\/ping.dcl","new_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Licensed to the Apache Software Foundation (ASF) under one or more\n$! contributor license agreements. See the NOTICE file distributed with\n$! this work for additional information regarding copyright ownership.\n$! The ASF licenses this file to You under the Apache License, Version 2.0\n$! (the \"License\"); you may not use this file except in compliance with\n$! the License. You may obtain a copy of the License at\n$!\n$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n$!\n$! Unless required by applicable law or agreed to in writing, software\n$! distributed under the License is distributed on an \"AS IS\" BASIS,\n$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n$! See the License for the specific language governing permissions and\n$! limitations under the License.\n$! \n$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! ping is started as subprocess which runs for 'P1' seconds\n$!\n$ write sys$output \"[ping.dcl] Blocking for ''P1' seconds ...\"\n$ tcpip ping 127.0.0.1 \/number_packets='P1 \/wait=1 ","old_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Licensed to the Apache Software Foundation (ASF) under one or more\n$! contributor license agreements. See the NOTICE file distributed with\n$! this work for additional information regarding copyright ownership.\n$! The ASF licenses this file to You under the Apache License, Version 2.0\n$! (the \"License\"); you may not use this file except in compliance with\n$! the License. You may obtain a copy of the License at\n$!\n$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n$!\n$! Unless required by applicable law or agreed to in writing, software\n$! distributed under the License is distributed on an \"AS IS\" BASIS,\n$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n$! See the License for the specific language governing permissions and\n$! limitations under the License.\n$! \n$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! ping is started as subprocess which runs for '%1' seconds\n$!\n$ write sys$output \"[ping.dcl] Blocking for %1 seconds ...\"\n$ tcpip ping 127.0.0.1 \/number_packets='P1 \/wait=1 ","returncode":0,"stderr":"","license":"apache-2.0","lang":"Clean"} {"commit":"936f7a03dbe41c7c415ba63ecbf64556edb0993e","subject":"add url shortening","message":"add url shortening\n","repos":"clean-cloogle\/clean-irc","old_file":"cloogle.icl","new_file":"cloogle.icl","new_contents":"module cloogle\n\nimport GenPrint\nimport IRC\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nfrom Data.Func import $\nfrom Text import class Text(..), instance Text String, instance + String\n\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad, instance Monad Maybe\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\n\ncommands :: [String]\ncommands = map toString\n\t[NICK \"clooglebot\"\n\t,USER \"cloogle\" 0 \"Cloogle bot\"\n\t,JOIN [(\"#cloogle\", Nothing)]\n\t]\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nKEY :== \"PRIVMSG #cloogle :!\"\n\ndoRequest :: HTTPRequest *World -> *(MaybeErrorString HTTPResponse, *World)\ndoRequest req w\n# (ip,w) = lookupIPAddress server_name w\n| isNothing ip\n\t= (Error $ \"DNS lookup for \" + server_name + \" failed.\", w)\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, req.server_port) w\n| rpt == TR_Expired\n\t= (Error $ \"Connection to \" + toString ip + \" timed out.\", w)\n| rpt == TR_NoSuccess\n\t= (Error $ \"Could not connect to \" + server_name + \".\", w)\n# (Just {sChannel,rChannel}) = chan\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq req) sChannel w\n| rpt <> TR_Success\n\t= (Error $ \"Could not send request to \" + server_name + \".\", w)\n# (rpt,resp,rChannel,w) = receive_MT TIMEOUT rChannel w\n| rpt <> TR_Success\n\t= (Error $ \"Did not receive a reply from \" + server_name + \".\", w)\n# resp = 'CM'.join $ parseResponse <$> toString <$> resp\n| isNothing resp\n\t# w = closeChannel sChannel (closeRChannel rChannel w)\n\t= (Error $ \"Server did not respond with HTTP.\", w)\n# (resp,rChannel,w) = receiveRest (fromJust resp) rChannel w\n# w = closeChannel sChannel (closeRChannel rChannel w)\n= (resp,w)\nwhere\n\tserver_name = req.server_name\n\treceiveRest resp chan w\n\t# cl = lookup \"Content-Length\" resp.HTTPResponse.rsp_headers\n\t| isNothing cl\n\t\t= (Ok resp, chan, w)\n\t| size resp.rsp_data >= toInt (fromJust cl)\n\t\t= (Ok resp, chan, w)\n\t# (rpt,newresp,chan,w) = receive_MT TIMEOUT chan w\n\t| rpt <> TR_Success\n\t\t= (Error $ server_name + \" hung up during transmission.\", chan, w)\n\t= receiveRest {resp & rsp_data=resp.rsp_data + toString (fromJust newresp)} chan w\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\nsend :: [String] TCP_DuplexChannel *World -> (TCP_DuplexChannel, *World)\nsend [] chan w = (chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = abort \"Could not send request\\n\"\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\nrecv :: TCP_DuplexChannel *World -> (Maybe String, TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = abort \"Halp?\\n\"\n= (toString <$> resp, {sChannel=sChannel,rChannel=rChannel}, w)\n\nmsg :: (String -> IRCCommands)\nmsg = PRIVMSG \"#cloogle\"\n\nprocess :: *File TCP_DuplexChannel *World -> (*File, TCP_DuplexChannel, *World)\nprocess io chan w \n# (mr, chan, w) = recv chan w\n| isNothing mr = process io chan w\n# resp = fromJust mr\n#! io = io <<< (\"Received: \" +++ resp +++ \"\\n\")\n# ind = indexOf KEY resp\n| ind >= 0\n\t# cmd = split \" \" $ rtrim $ subString (ind + size KEY) (size resp) resp\n\t#! io = io <<< (\"Received command: \" +++ printToString cmd +++ \"\\n\")\n\t# (w, toSend) = case cmd of\n\t\t[\"stop\":_] = (w, Nothing)\n\t\t[\"ping\":xs] = (w, Just [msg $ \"pong \" +++ join \" \" xs])\n\t\t[\"short\"] = (w, Just [msg $ \"short requires an url argument\"])\n\t\t[\"short\":xs]\n\t\t\t# (s, w) = shorten (join \" \" xs) w\n\t\t\t= (w, Just [msg s])\n\t\t[\"help\"] = (w, Just \n\t\t\t[msg \"type !help cmd for command specific help\"\n\t\t\t,msg \"available commands: help, short, ping\"])\n\t\t[\"help\":c:_] = (w, case c of\n\t\t\t\"help\" = Just [msg \"help [CMD] - I will print general help or the help of CMD\"] \n\t\t\t\"short\" = Just [msg \"short URL - I will give the url to https:\/\/cloo.gl shortening service and post back the result\"]\n\t\t\t\"ping\" = Just [msg \"ping [TXT] - I will reply with pong and the optionar TXT\"] \n\t\t\t_ = Just [msg \"Unknown command\"])\n\t\t[c:_] = (w, Just [msg $ join \" \" [\"unknown command: \" , c, \", type !help to get help\"]])\n\t| isNothing toSend = (io, chan, w)\n\t# (chan, w) = send (map toString $ fromJust toSend) chan w\n\t= process io chan w\n| indexOf \"PING :\" resp >= 0\n\t# cmd = rtrim $ subString (indexOf \"PING :\" resp + size \"PING :\") (size resp) resp\n\t#! io = io <<< (toString $ PONG cmd Nothing) <<< \"\\n\"\n\t# (chan, w) = send [toString $ PONG cmd Nothing] chan w\n\t= process io chan w\n= process io chan w\n\nStart :: *World -> *World\nStart w\n# (io, w) = stdio w\n# (ip, w) = lookupIPAddress SERVER w\n| isNothing ip = abort $ \"DNS lookup for \" +++ SERVER +++ \" failed\\n\"\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, 6667) w\n| rpt == TR_Expired = abort $ \"Connection to \" +++ SERVER +++ \" timed out\\n\"\n| rpt == TR_NoSuccess = abort $ \"Could not connect to \" +++ SERVER +++ \"\\n\"\n# chan = fromJust chan\n# (chan, w) = send commands chan w\n# (io, chan, w) = process io chan w\n# ({sChannel,rChannel}, w) = send [toString $ QUIT Nothing] chan w\n# (_, w) = fclose io w\n= closeChannel sChannel (closeRChannel rChannel w)\n","old_contents":"module cloogle\n\nimport GenPrint\nimport IRC\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nfrom Data.Func import $\nfrom Text import class Text(..), instance Text String\n\nimport TCPIP\n\ncommands :: [String]\ncommands = map toString\n\t[NICK \"clooglebot\"\n\t,USER \"cloogle\" 0 \"Cloogle bot\"\n\t,JOIN [(\"#cloogle\", Nothing)]\n\t]\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nKEY :== \"PRIVMSG #cloogle :!\"\n\nshorten :: String *World -> (String, *World)\nshorten s w = (\"not implemented yet\", w)\n\nsend :: [String] TCP_DuplexChannel *World -> (TCP_DuplexChannel, *World)\nsend [] chan w = (chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = abort \"Could not send request\\n\"\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\nrecv :: TCP_DuplexChannel *World -> (Maybe String, TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = abort \"Halp?\\n\"\n= (toString <$> resp, {sChannel=sChannel,rChannel=rChannel}, w)\n\nmsg :: (String -> IRCCommands)\nmsg = PRIVMSG \"#cloogle\"\n\nprocess :: *File TCP_DuplexChannel *World -> (*File, TCP_DuplexChannel, *World)\nprocess io chan w \n# (mr, chan, w) = recv chan w\n| isNothing mr = process io chan w\n# resp = fromJust mr\n#! io = io <<< (\"Received: \" +++ resp +++ \"\\n\")\n# ind = indexOf KEY resp\n| ind >= 0\n\t# cmd = split \" \" $ rtrim $ subString (ind + size KEY) (size resp) resp\n\t#! io = io <<< (\"Received command: \" +++ printToString cmd +++ \"\\n\")\n\t# (w, toSend) = case cmd of\n\t\t[\"stop\":_] = (w, Nothing)\n\t\t[\"ping\":xs] = (w, Just [msg $ \"pong \" +++ join \" \" xs])\n\t\t[\"short\"] = (w, Just [msg $ \"short requires an url argument\"])\n\t\t[\"short\":xs]\n\t\t\t# (s, w) = shorten (join \" \" xs) w\n\t\t\t= (w, Just [msg s])\n\t\t[\"help\"] = (w, Just \n\t\t\t[msg \"type !help cmd for command specific help\"\n\t\t\t,msg \"available commands: help, short, ping\"])\n\t\t[\"help\":c:_] = (w, case c of\n\t\t\t\"help\" = Just [msg \"help [CMD] - I will print general help or the help of CMD\"] \n\t\t\t\"short\" = Just [msg \"short URL - I will give the url to https:\/\/cloo.gl shortening service and post back the result\"]\n\t\t\t\"ping\" = Just [msg \"ping [TXT] - I will reply with pong and the optionar TXT\"] \n\t\t\t_ = Just [msg \"Unknown command\"])\n\t\t[c:_] = (w, Just [msg $ join \" \" [\"unknown command: \" , c, \", type !help to get help\"]])\n\t| isNothing toSend = (io, chan, w)\n\t# (chan, w) = send (map toString $ fromJust toSend) chan w\n\t= process io chan w\n| indexOf \"PING :\" resp >= 0\n\t# cmd = rtrim $ subString (indexOf \"PING :\" resp + size \"PING :\") (size resp) resp\n\t#! io = io <<< (toString $ PONG cmd Nothing) <<< \"\\n\"\n\t# (chan, w) = send [toString $ PONG cmd Nothing] chan w\n\t= process io chan w\n= process io chan w\n\nStart :: *World -> *World\nStart w\n# (io, w) = stdio w\n# (ip, w) = lookupIPAddress SERVER w\n| isNothing ip = abort $ \"DNS lookup for \" +++ SERVER +++ \" failed\\n\"\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, 6667) w\n| rpt == TR_Expired = abort $ \"Connection to \" +++ SERVER +++ \" timed out\\n\"\n| rpt == TR_NoSuccess = abort $ \"Could not connect to \" +++ SERVER +++ \"\\n\"\n# chan = fromJust chan\n# (chan, w) = send commands chan w\n# (io, chan, w) = process io chan w\n# ({sChannel,rChannel}, w) = send [toString $ QUIT Nothing] chan w\n# (_, w) = fclose io w\n= closeChannel sChannel (closeRChannel rChannel w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"f0eeaccec574e819ec1bc392280a6a4d682e7e3f","subject":"Fix print for multiple generic type vars","message":"Fix print for multiple generic type vars\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"TypeDB.icl","new_file":"TypeDB.icl","new_contents":"implementation module TypeDB\n\n\/\/ Standard libraries\nimport StdEnv\nfrom Data.Func import $\nfrom Data.List import intercalate\nimport Data.Map\nimport Data.Maybe\nimport Text.JSON\n\n\/\/ CleanTypeUnifier\nimport Type\n\n:: TypeDB = { functionmap :: Map FunctionLocation ExtendedType\n , classmap :: Map ClassLocation ([TypeVar],ClassContext,[(FunctionName, ExtendedType)])\n , instancemap :: Map Class [Type]\n , typemap :: Map TypeLocation TypeDef\n , derivemap :: Map GenericName [Type]\n }\n\nprintersperse :: Bool a [b] -> [String] | print a & print b\nprintersperse ia a bs = intercalate (print False a) (map (print ia) bs)\n\n(--) infixr 5 :: a b -> [String] | print a & print b\n(--) a b = print False a ++ print False b\n\nderive gEq ClassOrGeneric, FunctionLocation, ClassLocation, Type, TypeDB,\n\tTypeExtras, TE_Priority, ExtendedType, TypeDef, TypeLocation, TypeDefRhs,\n\tRecordField, Constructor, Kind\nderive JSONEncode ClassOrGeneric, FunctionLocation, ClassLocation, Type,\n\tTypeDB, TypeExtras, TE_Priority, ExtendedType, TypeDef, TypeLocation,\n\tTypeDefRhs, RecordField, Constructor, Kind\nderive JSONDecode ClassOrGeneric, FunctionLocation, ClassLocation, Type,\n\tTypeDB, TypeExtras, TE_Priority, ExtendedType, TypeDef, TypeLocation,\n\tTypeDefRhs, RecordField, Constructor, Kind\n\ninstance zero TypeDB\nwhere\n\tzero = { functionmap = newMap\n\t , classmap = newMap\n\t , instancemap = newMap\n\t , typemap = newMap\n\t , derivemap = newMap\n\t }\n\ninstance < FunctionLocation where (<) (FL a b c) (FL d e f) = (a,b,c) < (d,e,f)\ninstance print FunctionLocation\nwhere print _ (FL lib mod fn) = fn -- \" in \" -- mod -- \" in \" -- lib\n\ninstance < ClassLocation where (<) (CL a b c) (CL d e f) = (a,b,c) < (d,e,f)\n\ninstance < TypeLocation where (<) (TL a b c) (TL d e f) = (a,b,c) < (d,e,f)\n\ninstance zero TypeExtras\nwhere\n\tzero = { te_priority = Nothing\n\t , te_isconstructor = False\n\t , te_generic_vars = Nothing\n\t }\n\ninstance print TypeExtras\nwhere\n\tprint b {te_priority=Just p} = print b p -- \" \"\n\tprint b {te_generic_vars=Just vars} = printersperse b \" \" vars -- \" \"\n\tprint _ _ = []\n\ninstance print TE_Priority\nwhere\n\tprint _ (LeftAssoc i) = \"infixl \" -- i\n\tprint _ (RightAssoc i) = \"infixr \" -- i\n\tprint _ (NoAssoc i) = \"infix \" -- i\n\ninstance print (FunctionName, ExtendedType)\nwhere\n\tprint _ (f, (ET t e=:{te_generic_vars=Just _}))\n\t\t= \"generic \" -- f -- \" \" -- e -- \" :: \" -- t\n\tprint _ (f, (ET t e))\n\t\t= f -- \" \" -- e -- \" :: \" -- t\n\ngetFunction :: FunctionLocation TypeDB -> Maybe ExtendedType\ngetFunction loc {functionmap} = get loc functionmap\n\nputFunction :: FunctionLocation ExtendedType TypeDB -> TypeDB\nputFunction fl t tdb=:{functionmap} = { tdb & functionmap = put fl t functionmap }\n\nputFunctions :: [(FunctionLocation, ExtendedType)] TypeDB -> TypeDB\nputFunctions ts tdb = foldr (\\(loc,t) db -> putFunction loc t db) tdb ts\n\nfindFunction :: FunctionName TypeDB -> [(FunctionLocation, ExtendedType)]\nfindFunction f db=:{functionmap}\n\t= toList $ filterWithKey (\\(FL _ _ f`) _->f==f`) functionmap\n\nfindFunction` :: (FunctionLocation ExtendedType -> Bool) TypeDB\n\t-> [(FunctionLocation, ExtendedType)]\nfindFunction` f {functionmap} = toList $ filterWithKey f functionmap\n\nfindFunction`` :: [(FunctionLocation ExtendedType -> Bool)] TypeDB\n\t-> [(FunctionLocation, ExtendedType)]\nfindFunction`` fs {functionmap} = toList $ foldr filterWithKey functionmap fs\n\ngetInstances :: Class TypeDB -> [Type]\ngetInstances c {instancemap} = if (isNothing ts) [] (fromJust ts)\nwhere ts = get c instancemap\n\nputInstance :: Class Type TypeDB -> TypeDB\nputInstance c t db=:{instancemap} = {db & instancemap=put c ts instancemap}\nwhere ts = removeDup [t : getInstances c db]\n\nputInstances :: Class [Type] TypeDB -> TypeDB\nputInstances c ts db = foldr (\\t db -> putInstance c t db) db ts\n\nputInstancess :: [(Class, [Type])] TypeDB -> TypeDB\nputInstancess is db = foldr (\\(c,ts) db -> putInstances c ts db) db is\n\ngetClass :: ClassLocation TypeDB -> Maybe ([TypeVar],ClassContext,[(FunctionName,ExtendedType)])\ngetClass loc {classmap} = get loc classmap\n\nputClass :: ClassLocation [TypeVar] ClassContext [(FunctionName, ExtendedType)] TypeDB -> TypeDB\nputClass cl tvs cc fs db=:{classmap} = {db & classmap = put cl (tvs,cc,fs) classmap}\n\nputClasses :: [(ClassLocation, [TypeVar], ClassContext, [(FunctionName, ExtendedType)])] TypeDB -> TypeDB\nputClasses cs db = foldr (\\(cl,tvs,cc,fs) db -> putClass cl tvs cc fs db) db cs\n\nfindClass :: Class TypeDB -> [(ClassLocation, [TypeVar], ClassContext, [(FunctionName, ExtendedType)])]\nfindClass c {classmap} = map (\\(k,(x,y,z))->(k,x,y,z)) results\nwhere results = toList $ filterWithKey (\\(CL _ _ c`) _->c==c`) classmap\n\nfindClass` :: (ClassLocation [TypeVar] ClassContext [(FunctionName,ExtendedType)] -> Bool) TypeDB\n\t\t-> [(ClassLocation, [TypeVar], ClassContext, [(FunctionName,ExtendedType)])]\nfindClass` f {classmap} = map (\\(k,(x,y,z))->(k,x,y,z)) results\nwhere results = toList $ filterWithKey (\\cl (vs,cc,fs)->f cl vs cc fs) classmap\n\nfindClassMembers` :: (ClassLocation [TypeVar] ClassContext FunctionName ExtendedType -> Bool) TypeDB\n\t\t-> [(ClassLocation, [TypeVar], ClassContext, FunctionName, ExtendedType)]\nfindClassMembers` f {classmap} = filter (app5 f) $ flatten members\nwhere\n\tmembers = map (\\(cl,(vs,cc,fs))->[(cl,vs,cc,f,t) \\\\ (f,t)<-fs]) $ toList classmap\n\nfindClassMembers`` :: [(ClassLocation [TypeVar] ClassContext FunctionName ExtendedType -> Bool)]\n\t\tTypeDB -> [(ClassLocation, [TypeVar], ClassContext, FunctionName, ExtendedType)]\nfindClassMembers`` fs {classmap} = foldr (filter o app5) all_members fs\nwhere\n\tall_members = [(cl,vs,cc,f,t) \\\\ (cl,(vs,cc,fs)) <- toList classmap, (f,t) <- fs]\n\ngetType :: TypeLocation TypeDB -> Maybe TypeDef\ngetType loc {typemap} = get loc typemap\n\nputType :: TypeLocation TypeDef TypeDB -> TypeDB\nputType tl td db=:{typemap} = {db & typemap = put tl td typemap}\n\nputTypes :: [(TypeLocation, TypeDef)] TypeDB -> TypeDB\nputTypes ts db = foldr (\\(loc,td) -> putType loc td) db ts\n\nfindType :: TypeName TypeDB -> [(TypeLocation, TypeDef)]\nfindType t db=:{typemap}\n\t= toList $ filterWithKey (\\(TL _ _ t`) _->t==t`) typemap\n\nfindType` :: (TypeLocation TypeDef -> Bool) TypeDB\n\t\t-> [(TypeLocation, TypeDef)]\nfindType` f {typemap} = toList $ filterWithKey f typemap\n\ngetDerivations :: GenericName TypeDB -> [Type]\ngetDerivations gen {derivemap} = if (isNothing ts) [] (fromJust ts)\nwhere ts = get gen derivemap\n\nputDerivation :: GenericName Type TypeDB -> TypeDB\nputDerivation gen t db=:{derivemap} = {db & derivemap=put gen ts derivemap}\nwhere ts = removeDup [t : getDerivations gen db]\n\nputDerivations :: GenericName [Type] TypeDB -> TypeDB\nputDerivations gen ts db = foldr (\\t db -> putDerivation gen t db) db ts\n\nputDerivationss :: [(GenericName, [Type])] TypeDB -> TypeDB\nputDerivationss ds db = foldr (\\(g,ts) db -> putDerivations g ts db) db ds\n\nsearchExact :: Type TypeDB -> [(FunctionLocation, ExtendedType)]\nsearchExact t db = filter ((\\(ET t` _)->t==t`) o snd) $ toList db.functionmap\n\nnewDb :: TypeDB\nnewDb = zero\n\nopenDb :: *File -> *(Maybe TypeDB, *File)\nopenDb f\n# (data, f) = freadline f\n= (fromJSON $ fromString data, f)\n\nsaveDb :: TypeDB *File -> *File\nsaveDb db f = fwrites (toString $ toJSON db) f\n\napp5 f (a,b,c,d,e) :== f a b c d e\n","old_contents":"implementation module TypeDB\n\n\/\/ Standard libraries\nimport StdEnv\nfrom Data.Func import $\nimport Data.Map\nimport Data.Maybe\nimport Text.JSON\n\n\/\/ CleanTypeUnifier\nimport Type\n\n:: TypeDB = { functionmap :: Map FunctionLocation ExtendedType\n , classmap :: Map ClassLocation ([TypeVar],ClassContext,[(FunctionName, ExtendedType)])\n , instancemap :: Map Class [Type]\n , typemap :: Map TypeLocation TypeDef\n , derivemap :: Map GenericName [Type]\n }\n\n(--) infixr 5 :: a b -> [String] | print a & print b\n(--) a b = print False a ++ print False b\n\nderive gEq ClassOrGeneric, FunctionLocation, ClassLocation, Type, TypeDB,\n\tTypeExtras, TE_Priority, ExtendedType, TypeDef, TypeLocation, TypeDefRhs,\n\tRecordField, Constructor, Kind\nderive JSONEncode ClassOrGeneric, FunctionLocation, ClassLocation, Type,\n\tTypeDB, TypeExtras, TE_Priority, ExtendedType, TypeDef, TypeLocation,\n\tTypeDefRhs, RecordField, Constructor, Kind\nderive JSONDecode ClassOrGeneric, FunctionLocation, ClassLocation, Type,\n\tTypeDB, TypeExtras, TE_Priority, ExtendedType, TypeDef, TypeLocation,\n\tTypeDefRhs, RecordField, Constructor, Kind\n\ninstance zero TypeDB\nwhere\n\tzero = { functionmap = newMap\n\t , classmap = newMap\n\t , instancemap = newMap\n\t , typemap = newMap\n\t , derivemap = newMap\n\t }\n\ninstance < FunctionLocation where (<) (FL a b c) (FL d e f) = (a,b,c) < (d,e,f)\ninstance print FunctionLocation\nwhere print _ (FL lib mod fn) = fn -- \" in \" -- mod -- \" in \" -- lib\n\ninstance < ClassLocation where (<) (CL a b c) (CL d e f) = (a,b,c) < (d,e,f)\n\ninstance < TypeLocation where (<) (TL a b c) (TL d e f) = (a,b,c) < (d,e,f)\n\ninstance zero TypeExtras\nwhere\n\tzero = { te_priority = Nothing\n\t , te_isconstructor = False\n\t , te_generic_vars = Nothing\n\t }\n\ninstance print TypeExtras\nwhere\n\tprint b {te_priority=Just p} = print b p -- \" \"\n\tprint b {te_generic_vars=Just vars} = print b vars -- \" \"\n\tprint _ _ = []\n\ninstance print TE_Priority\nwhere\n\tprint _ (LeftAssoc i) = \"infixl \" -- i\n\tprint _ (RightAssoc i) = \"infixr \" -- i\n\tprint _ (NoAssoc i) = \"infix \" -- i\n\ninstance print (FunctionName, ExtendedType)\nwhere\n\tprint _ (f, (ET t e=:{te_generic_vars=Just _}))\n\t\t= \"generic \" -- f -- \" \" -- e -- \" :: \" -- t\n\tprint _ (f, (ET t e))\n\t\t= f -- \" \" -- e -- \" :: \" -- t\n\ngetFunction :: FunctionLocation TypeDB -> Maybe ExtendedType\ngetFunction loc {functionmap} = get loc functionmap\n\nputFunction :: FunctionLocation ExtendedType TypeDB -> TypeDB\nputFunction fl t tdb=:{functionmap} = { tdb & functionmap = put fl t functionmap }\n\nputFunctions :: [(FunctionLocation, ExtendedType)] TypeDB -> TypeDB\nputFunctions ts tdb = foldr (\\(loc,t) db -> putFunction loc t db) tdb ts\n\nfindFunction :: FunctionName TypeDB -> [(FunctionLocation, ExtendedType)]\nfindFunction f db=:{functionmap}\n\t= toList $ filterWithKey (\\(FL _ _ f`) _->f==f`) functionmap\n\nfindFunction` :: (FunctionLocation ExtendedType -> Bool) TypeDB\n\t-> [(FunctionLocation, ExtendedType)]\nfindFunction` f {functionmap} = toList $ filterWithKey f functionmap\n\nfindFunction`` :: [(FunctionLocation ExtendedType -> Bool)] TypeDB\n\t-> [(FunctionLocation, ExtendedType)]\nfindFunction`` fs {functionmap} = toList $ foldr filterWithKey functionmap fs\n\ngetInstances :: Class TypeDB -> [Type]\ngetInstances c {instancemap} = if (isNothing ts) [] (fromJust ts)\nwhere ts = get c instancemap\n\nputInstance :: Class Type TypeDB -> TypeDB\nputInstance c t db=:{instancemap} = {db & instancemap=put c ts instancemap}\nwhere ts = removeDup [t : getInstances c db]\n\nputInstances :: Class [Type] TypeDB -> TypeDB\nputInstances c ts db = foldr (\\t db -> putInstance c t db) db ts\n\nputInstancess :: [(Class, [Type])] TypeDB -> TypeDB\nputInstancess is db = foldr (\\(c,ts) db -> putInstances c ts db) db is\n\ngetClass :: ClassLocation TypeDB -> Maybe ([TypeVar],ClassContext,[(FunctionName,ExtendedType)])\ngetClass loc {classmap} = get loc classmap\n\nputClass :: ClassLocation [TypeVar] ClassContext [(FunctionName, ExtendedType)] TypeDB -> TypeDB\nputClass cl tvs cc fs db=:{classmap} = {db & classmap = put cl (tvs,cc,fs) classmap}\n\nputClasses :: [(ClassLocation, [TypeVar], ClassContext, [(FunctionName, ExtendedType)])] TypeDB -> TypeDB\nputClasses cs db = foldr (\\(cl,tvs,cc,fs) db -> putClass cl tvs cc fs db) db cs\n\nfindClass :: Class TypeDB -> [(ClassLocation, [TypeVar], ClassContext, [(FunctionName, ExtendedType)])]\nfindClass c {classmap} = map (\\(k,(x,y,z))->(k,x,y,z)) results\nwhere results = toList $ filterWithKey (\\(CL _ _ c`) _->c==c`) classmap\n\nfindClass` :: (ClassLocation [TypeVar] ClassContext [(FunctionName,ExtendedType)] -> Bool) TypeDB\n\t\t-> [(ClassLocation, [TypeVar], ClassContext, [(FunctionName,ExtendedType)])]\nfindClass` f {classmap} = map (\\(k,(x,y,z))->(k,x,y,z)) results\nwhere results = toList $ filterWithKey (\\cl (vs,cc,fs)->f cl vs cc fs) classmap\n\nfindClassMembers` :: (ClassLocation [TypeVar] ClassContext FunctionName ExtendedType -> Bool) TypeDB\n\t\t-> [(ClassLocation, [TypeVar], ClassContext, FunctionName, ExtendedType)]\nfindClassMembers` f {classmap} = filter (app5 f) $ flatten members\nwhere\n\tmembers = map (\\(cl,(vs,cc,fs))->[(cl,vs,cc,f,t) \\\\ (f,t)<-fs]) $ toList classmap\n\nfindClassMembers`` :: [(ClassLocation [TypeVar] ClassContext FunctionName ExtendedType -> Bool)]\n\t\tTypeDB -> [(ClassLocation, [TypeVar], ClassContext, FunctionName, ExtendedType)]\nfindClassMembers`` fs {classmap} = foldr (filter o app5) all_members fs\nwhere\n\tall_members = [(cl,vs,cc,f,t) \\\\ (cl,(vs,cc,fs)) <- toList classmap, (f,t) <- fs]\n\ngetType :: TypeLocation TypeDB -> Maybe TypeDef\ngetType loc {typemap} = get loc typemap\n\nputType :: TypeLocation TypeDef TypeDB -> TypeDB\nputType tl td db=:{typemap} = {db & typemap = put tl td typemap}\n\nputTypes :: [(TypeLocation, TypeDef)] TypeDB -> TypeDB\nputTypes ts db = foldr (\\(loc,td) -> putType loc td) db ts\n\nfindType :: TypeName TypeDB -> [(TypeLocation, TypeDef)]\nfindType t db=:{typemap}\n\t= toList $ filterWithKey (\\(TL _ _ t`) _->t==t`) typemap\n\nfindType` :: (TypeLocation TypeDef -> Bool) TypeDB\n\t\t-> [(TypeLocation, TypeDef)]\nfindType` f {typemap} = toList $ filterWithKey f typemap\n\ngetDerivations :: GenericName TypeDB -> [Type]\ngetDerivations gen {derivemap} = if (isNothing ts) [] (fromJust ts)\nwhere ts = get gen derivemap\n\nputDerivation :: GenericName Type TypeDB -> TypeDB\nputDerivation gen t db=:{derivemap} = {db & derivemap=put gen ts derivemap}\nwhere ts = removeDup [t : getDerivations gen db]\n\nputDerivations :: GenericName [Type] TypeDB -> TypeDB\nputDerivations gen ts db = foldr (\\t db -> putDerivation gen t db) db ts\n\nputDerivationss :: [(GenericName, [Type])] TypeDB -> TypeDB\nputDerivationss ds db = foldr (\\(g,ts) db -> putDerivations g ts db) db ds\n\nsearchExact :: Type TypeDB -> [(FunctionLocation, ExtendedType)]\nsearchExact t db = filter ((\\(ET t` _)->t==t`) o snd) $ toList db.functionmap\n\nnewDb :: TypeDB\nnewDb = zero\n\nopenDb :: *File -> *(Maybe TypeDB, *File)\nopenDb f\n# (data, f) = freadline f\n= (fromJSON $ fromString data, f)\n\nsaveDb :: TypeDB *File -> *File\nsaveDb db f = fwrites (toString $ toJSON db) f\n\napp5 f (a,b,c,d,e) :== f a b c d e\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"51b8c91d8b9dac126d5294702714ad6ecbb9a39e","subject":"Log only after forking (investigating #113)","message":"Log only after forking (investigating #113)\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/SimpleTCPServer.icl","new_file":"backend\/SimpleTCPServer.icl","new_contents":"implementation module SimpleTCPServer\n\nimport TCPIP\nimport StdEnv\nimport StdMaybe\nimport System._Posix\n\nTIMEOUT :== Just 5000\n\ninstance zero (Logger a b s t) where zero = \\_ _ w -> (undef, w)\n\nserve :: (a *World -> *(b,t,*World)) (Maybe (Logger a b s t)) Port *World\n\t-> *World | fromString a & toString b\nserve f log port w\n# (ok, mbListener, w) = openTCP_Listener port w\n| not ok = abort (\"Couldn't open port \" +++ toString port +++ \"\\n\")\n# listener = fromJust mbListener\n# log = if (isNothing log) zero (fromJust log)\n# (_,w) = signal 17 1 w \/\/ SIGCHLD, SIG_IGN: no notification if child ps dies\n# (listener, w) = loop f log listener w\n= closeRChannel listener w\nwhere\n\tloop :: (a *World -> *(b,t,*World)) (Logger a b s t) TCP_Listener *World\n\t\t-> (TCP_Listener, *World) | fromString a & toString b\n\tloop f log li w\n\t#! ((ip,dupChan),li,w) = receive li w\n\t# (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = loop f log li w \/\/ Parent: handle new requests\n\t#! (st,w) = log (Connected ip) Nothing w\n\t= handle f log st dupChan w \/\/ Child: handle current request\n\n\thandle :: (a *World-> (b,t,*World)) (Logger a b s t) !(Maybe !s) !TCP_DuplexChannel\n\t\t!*World -> (TCP_Listener, *World) | fromString a & toString b\n\thandle f log st dupChannel=:{rChannel,sChannel} w\n\t# (tRep,msg,rChannel,w) = receive_MT TIMEOUT rChannel w\n\t| tRep <> TR_Success\n\t\t# (st,w) = log Disconnected st w\n\t\t# w = closeChannel sChannel (closeRChannel rChannel w)\n\t\t= exit 0 w\n\t# msg = fromString (toString (fromJust msg))\n\t# (st, w) = log (Received msg) st w\n\t# (resp, hidden, w) = f msg w\n\t# (sChannel, w) = send (toByteSeq (toString resp)) sChannel w\n\t# (st, w) = log (Sent resp hidden) st w\n\t= handle f log st {dupChannel & rChannel=rChannel, sChannel=sChannel} w\n\nsignal :: !Int !Int !*World -> *(!Int, !*World)\nsignal signum handler w = code {\n\tccall signal \"II:I:A\"\n}\n","old_contents":"implementation module SimpleTCPServer\n\nimport TCPIP\nimport StdEnv\nimport StdMaybe\nimport System._Posix\n\nTIMEOUT :== Just 5000\n\ninstance zero (Logger a b s t) where zero = \\_ _ w -> (undef, w)\n\nserve :: (a *World -> *(b,t,*World)) (Maybe (Logger a b s t)) Port *World\n\t-> *World | fromString a & toString b\nserve f log port w\n# (ok, mbListener, w) = openTCP_Listener port w\n| not ok = abort (\"Couldn't open port \" +++ toString port +++ \"\\n\")\n# listener = fromJust mbListener\n# log = if (isNothing log) zero (fromJust log)\n# (_,w) = signal 17 1 w \/\/ SIGCHLD, SIG_IGN: no notification if child ps dies\n# (listener, w) = loop f log listener w\n= closeRChannel listener w\nwhere\n\tloop :: (a *World -> *(b,t,*World)) (Logger a b s t) TCP_Listener *World\n\t\t-> (TCP_Listener, *World) | fromString a & toString b\n\tloop f log li w\n\t#! ((ip,dupChan),li,w) = receive li w\n\t#! (st,w) = log (Connected ip) Nothing w\n\t# (pid,w) = fork w\n\t| pid < 0\n\t\t= abort \"fork failed\\n\"\n\t| pid > 0\n\t\t\/\/ Parent: handle new requests\n\t\t= loop f log li w\n\t\t\/\/ Child: handle current request\n\t\t= handle f log st dupChan w\n\n\thandle :: (a *World-> (b,t,*World)) (Logger a b s t) !(Maybe !s) !TCP_DuplexChannel\n\t\t!*World -> (TCP_Listener, *World) | fromString a & toString b\n\thandle f log st dupChannel=:{rChannel,sChannel} w\n\t# (tRep,msg,rChannel,w) = receive_MT TIMEOUT rChannel w\n\t| tRep <> TR_Success\n\t\t# (st,w) = log Disconnected st w\n\t\t# w = closeChannel sChannel (closeRChannel rChannel w)\n\t\t= exit 0 w\n\t# msg = fromString (toString (fromJust msg))\n\t# (st, w) = log (Received msg) st w\n\t# (resp, hidden, w) = f msg w\n\t# (sChannel, w) = send (toByteSeq (toString resp)) sChannel w\n\t# (st, w) = log (Sent resp hidden) st w\n\t= handle f log st {dupChannel & rChannel=rChannel, sChannel=sChannel} w\n\nsignal :: !Int !Int !*World -> *(!Int, !*World)\nsignal signum handler w = code {\n\tccall signal \"II:I:A\"\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"81302cd8106d6433468460dd42b36c43d64d6fa7","subject":"Fix documentation of A in ccall (#189); invalidates #190","message":"Fix documentation of A in ccall (#189); invalidates #190\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle","old_file":"backend\/Builtin\/ABC.icl","new_file":"backend\/Builtin\/ABC.icl","new_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t, i_push_r_arg_t\n\t, i_push_t_r_a\n\t, i_push_t_r_args\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \" - sep can be either `-` or `:`.\"\n\t\t\t, \" - flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \" - input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t\t, \" - output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t\t, \" - state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \" - `I` for integers\"\n\t\t\t, \" - `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \" - [`Rr`] for reals\"\n\t\t\t, \" - `S` for Clean Strings (`{#Char}`). If used as input type this passes a pointer to the string's length (number of characters). The actual array is at offset 4\/8 (32\/64 bit). If this is used as output type, the C function has to return a pointer to the string's length, followed by the actual string. A copy of the string will be created in the Clean heap, and this copy will be used by Clean. If the string was allocated in C, for example using malloc, it should be deallocated in C when it no longer used, it is not automatically deallocated by Clean.\"\n\t\t\t, \" - `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}}, as the string is not null-terminated). The length (number of characters) is at offset -4\/-8. (32\/64 bit).\"\n\t\t\t, \" - `A` for A-stack elements. A pointer to the third block of the node is passed. For arrays, this is a pointer to the elements. The size of the array is one word higher in the block.\"\n\t\t\t, \" - [`OF`] for function pointers\"\n\t\t\t, \" - `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\n\ti_push_r_arg_t =\n\t\t{ zero\n\t\t& aie_instruction = \"push_r_arg_t\"\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Gets the *n*th element from the type string of a record.\"\n\t\t\t, \"The type string is on top of the B-stack; *n* below that.\"\n\t\t\t]\n\t\t}\n\ti_push_t_r_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Push the address of the type string of the referenced record to the B-stack.\"\n\t\t}\n\ti_push_t_r_args =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_args\"\n\t\t, aie_description = \"Pops a record from the A-stack, pushes its members in reversed order to both of the stacks, then pushes the address of the type string to the B-stack.\"\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_n\n\t, d_nu\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_n =\n\t\t{ zero\n\t\t& aie_instruction = \".n\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t, \"\\n\\nThere are some special cases:\\n\\n\"\n\t\t\t, \"- An arity of `-1` is for tuple selectors;\\n\"\n\t\t\t, \"- An arity of `-2` is for indirection nodes;\\n\"\n\t\t\t, \"- An arity of `-3` is for record selectors of basic types;\\n\"\n\t\t\t, \"- An arity of `-4` is for record selectors of non-basic types.\\n\\n\"\n\t\t\t, \"See also {{`.nu`}}.\"\n\t\t\t]\n\t\t}\n\td_nu =\n\t\t{ zero\n\t\t& aie_instruction = \".nu\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels with arguments on the B-stack (otherwise, {{`.n`}} is used).\"\n\t\t\t, \"The first integer is the number of A-stack arguments; the second the number of B-stack arguments.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_a_b\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","old_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t, i_push_r_arg_t\n\t, i_push_t_r_a\n\t, i_push_t_r_args\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \" - sep can be either `-` or `:`.\"\n\t\t\t, \" - flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \" - input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t\t, \" - output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t\t, \" - state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \" - `I` for integers\"\n\t\t\t, \" - `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \" - [`Rr`] for reals\"\n\t\t\t, \" - `S` for Clean Strings (`{#Char}`). If used as input type this passes a pointer to the string's length (number of characters). The actual array is at offset 4\/8 (32\/64 bit). If this is used as output type, the C function has to return a pointer to the string's length, followed by the actual string. A copy of the string will be created in the Clean heap, and this copy will be used by Clean. If the string was allocated in C, for example using malloc, it should be deallocated in C when it no longer used, it is not automatically deallocated by Clean.\"\n\t\t\t, \" - `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}}, as the string is not null-terminated). The length (number of characters) is at offset -4\/-8. (32\/64 bit).\"\n\t\t\t, \" - `A` for A-stack elements, which can be:\"\n\t\t\t, \" * `*World`, which is a boxed integer under the hood\"\n\t\t\t, \" * integer or real arrays (`{#Int}` or `{#Real}`). This passes a pointer to the array. The length (number of integers\/reals) is at offset -8\/-16 (32\/64 bit).\"\n\t\t\t, \" - [`OF`] for function pointers\"\n\t\t\t, \" - `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\n\ti_push_r_arg_t =\n\t\t{ zero\n\t\t& aie_instruction = \"push_r_arg_t\"\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Gets the *n*th element from the type string of a record.\"\n\t\t\t, \"The type string is on top of the B-stack; *n* below that.\"\n\t\t\t]\n\t\t}\n\ti_push_t_r_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Push the address of the type string of the referenced record to the B-stack.\"\n\t\t}\n\ti_push_t_r_args =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_args\"\n\t\t, aie_description = \"Pops a record from the A-stack, pushes its members in reversed order to both of the stacks, then pushes the address of the type string to the B-stack.\"\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_n\n\t, d_nu\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_n =\n\t\t{ zero\n\t\t& aie_instruction = \".n\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t, \"\\n\\nThere are some special cases:\\n\\n\"\n\t\t\t, \"- An arity of `-1` is for tuple selectors;\\n\"\n\t\t\t, \"- An arity of `-2` is for indirection nodes;\\n\"\n\t\t\t, \"- An arity of `-3` is for record selectors of basic types;\\n\"\n\t\t\t, \"- An arity of `-4` is for record selectors of non-basic types.\\n\\n\"\n\t\t\t, \"See also {{`.nu`}}.\"\n\t\t\t]\n\t\t}\n\td_nu =\n\t\t{ zero\n\t\t& aie_instruction = \".nu\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels with arguments on the B-stack (otherwise, {{`.n`}} is used).\"\n\t\t\t, \"The first integer is the number of A-stack arguments; the second the number of B-stack arguments.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_a_b\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"78cb1e76c5a63d3670c3ff4eda3ce9b723f57fba","subject":"stub for shortening","message":"stub for shortening\n","repos":"clean-cloogle\/clean-irc","old_file":"cloogle.icl","new_file":"cloogle.icl","new_contents":"module cloogle\n\nimport GenPrint\nimport IRC\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nfrom Data.Func import $\nfrom Text import class Text(..), instance Text String\n\nimport TCPIP\n\ncommands :: [String]\ncommands = map toString\n\t[NICK \"clooglebot\"\n\t,USER \"cloogle\" 0 \"Cloogle bot\"\n\t,JOIN [(\"#cloogle\", Nothing)]\n\t]\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nKEY :== \"PRIVMSG #cloogle :!\"\n\nshorten :: String *World -> (String, *World)\nshorten s w = (\"not implemented yet\", w)\n\nsend :: [String] TCP_DuplexChannel *World -> (TCP_DuplexChannel, *World)\nsend [] chan w = (chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = abort \"Could not send request\\n\"\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\nrecv :: TCP_DuplexChannel *World -> (Maybe String, TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = abort \"Halp?\\n\"\n= (toString <$> resp, {sChannel=sChannel,rChannel=rChannel}, w)\n\nmsg :: (String -> IRCCommands)\nmsg = PRIVMSG \"#cloogle\"\n\nprocess :: *File TCP_DuplexChannel *World -> (*File, TCP_DuplexChannel, *World)\nprocess io chan w \n# (mr, chan, w) = recv chan w\n| isNothing mr = process io chan w\n# resp = fromJust mr\n#! io = io <<< (\"Received: \" +++ resp +++ \"\\n\")\n# ind = indexOf KEY resp\n| ind >= 0\n\t# cmd = split \" \" $ rtrim $ subString (ind + size KEY) (size resp) resp\n\t#! io = io <<< (\"Received command: \" +++ printToString cmd +++ \"\\n\")\n\t# (w, toSend) = case cmd of\n\t\t[\"stop\":_] = (w, Nothing)\n\t\t[\"ping\":xs] = (w, Just [msg $ \"pong \" +++ join \" \" xs])\n\t\t[\"short\"] = (w, Just [msg $ \"short requires an url argument\"])\n\t\t[\"short\":xs]\n\t\t\t# (s, w) = shorten (join \" \" xs) w\n\t\t\t= (w, Just [msg s])\n\t\t[\"help\"] = (w, Just \n\t\t\t[msg \"type !help cmd for command specific help\"\n\t\t\t,msg \"available commands: help, short, ping\"])\n\t\t[\"help\":c:_] = (w, case c of\n\t\t\t\"help\" = Just [msg \"help [CMD] - I will print general help or the help of CMD\"] \n\t\t\t\"short\" = Just [msg \"short URL - I will give the url to https:\/\/cloo.gl shortening service and post back the result\"]\n\t\t\t\"ping\" = Just [msg \"ping [TXT] - I will reply with pong and the optionar TXT\"] \n\t\t\t_ = Just [msg \"Unknown command\"])\n\t\t[c:_] = (w, Just [msg $ join \" \" [\"unknown command: \" , c, \", type !help to get help\"]])\n\t| isNothing toSend = (io, chan, w)\n\t# (chan, w) = send (map toString $ fromJust toSend) chan w\n\t= process io chan w\n| indexOf \"PING :\" resp >= 0\n\t# cmd = rtrim $ subString (indexOf \"PING :\" resp + size \"PING :\") (size resp) resp\n\t#! io = io <<< (toString $ PONG cmd Nothing) <<< \"\\n\"\n\t# (chan, w) = send [toString $ PONG cmd Nothing] chan w\n\t= process io chan w\n= process io chan w\n\nStart :: *World -> *World\nStart w\n# (io, w) = stdio w\n# (ip, w) = lookupIPAddress SERVER w\n| isNothing ip = abort $ \"DNS lookup for \" +++ SERVER +++ \" failed\\n\"\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, 6667) w\n| rpt == TR_Expired = abort $ \"Connection to \" +++ SERVER +++ \" timed out\\n\"\n| rpt == TR_NoSuccess = abort $ \"Could not connect to \" +++ SERVER +++ \"\\n\"\n# chan = fromJust chan\n# (chan, w) = send commands chan w\n# (io, chan, w) = process io chan w\n# ({sChannel,rChannel}, w) = send [toString $ QUIT Nothing] chan w\n# (_, w) = fclose io w\n= closeChannel sChannel (closeRChannel rChannel w)\n","old_contents":"module cloogle\n\nimport GenPrint\nimport IRC\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nfrom Data.Func import $\nfrom Text import class Text(..), instance Text String\n\nimport TCPIP\n\ncommands :: [String]\ncommands = map toString\n\t[NICK \"clooglebot\"\n\t,USER \"cloogle\" 0 \"Cloogle bot\"\n\t,JOIN [(\"#cloogle\", Nothing)]\n\t]\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nKEY :== \"PRIVMSG #cloogle :!\"\n\nsend :: [String] TCP_DuplexChannel *World -> (TCP_DuplexChannel, *World)\nsend [] chan w = (chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = abort \"Could not send request\\n\"\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\nrecv :: TCP_DuplexChannel *World -> (Maybe String, TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = abort \"Halp?\\n\"\n= (toString <$> resp, {sChannel=sChannel,rChannel=rChannel}, w)\n\nmsg :: (String -> IRCCommands)\nmsg = PRIVMSG \"#cloogle\"\n\nprocess :: *File TCP_DuplexChannel *World -> (*File, TCP_DuplexChannel, *World)\nprocess io chan w \n# (mr, chan, w) = recv chan w\n| isNothing mr = process io chan w\n# resp = fromJust mr\n#! io = io <<< (\"Received: \" +++ resp +++ \"\\n\")\n# ind = indexOf KEY resp\n| ind > 0\n\t# cmd = split \" \" $ rtrim $ subString (ind + size KEY) (size resp) resp\n\t#! io = io <<< (\"Received command: \" +++ printToString cmd +++ \"\\n\")\n\t# toSend = case cmd of\n\t\t[\"stop\":_] = Nothing\n\t\t[\"ping\":xs] = Just [msg $ \"pong \" +++ join \" \" xs]\n\t\t[\"help\"] = Just \n\t\t\t[msg \"type !help cmd for command specific help\"\n\t\t\t,msg \"available commands: help, ping\"]\n\t\t[\"help\":c:_] = case c of\n\t\t\t\"help\" = Just [msg \"help [CMD] - I will print general help or the help of CMD\"] \n\t\t\t\"ping\" = Just [msg \"ping [TXT] - I will reply with pong and the optionar TXT\"] \n\t\t\t_ = Just [msg \"Unknown command\"]\n\t\t[c:_] = Just [msg $ join \" \" [\"unknown command: \" , c, \", type !help to get help\"]]\n\t| isNothing toSend = (io, chan, w)\n\t# (chan, w) = send (map toString $ fromJust toSend) chan w\n\t= process io chan w\n| indexOf \"PING :\" resp > 0\n\t# cmd = rtrim $ subString (indexOf \"PING :\" resp + size \"PING :\") (size resp) resp\n\t#! io <<< (toString $ PONG cmd Nothing) <<< \"\\n\"\n\t# (chan, w) = send [toString $ PONG cmd Nothing] chan w\n\t= process io chan w\n= process io chan w\n\nStart :: *World -> *World\nStart w\n# (io, w) = stdio w\n# (ip, w) = lookupIPAddress SERVER w\n| isNothing ip = abort $ \"DNS lookup for \" +++ SERVER +++ \" failed\\n\"\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, 6667) w\n| rpt == TR_Expired = abort $ \"Connection to \" +++ SERVER +++ \" timed out\\n\"\n| rpt == TR_NoSuccess = abort $ \"Could not connect to \" +++ SERVER +++ \"\\n\"\n# chan = fromJust chan\n# (chan, w) = send commands chan w\n# (io, chan, w) = process io chan w\n# ({sChannel,rChannel}, w) = send [toString $ QUIT Nothing] chan w\n# (_, w) = fclose io w\n= closeChannel sChannel (closeRChannel rChannel w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"fa59c509fb9fc6801e4e36393166a8da8bf1385c","subject":"Cache all requests but don't override nonzero response code","message":"Cache all requests but don't override nonzero response code\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , libraries :: Maybe ([String], Bool)\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , dcl_line :: Maybe Int\n , distance :: Int\n , builtin :: Maybe Bool\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , recordfield_of :: Maybe String\n , generic_derivations :: Maybe [(String, [(String,String,Maybe Int)])]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [(String, [(String,String,Maybe Int)])]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = MaybeError Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , libraries = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache request w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err E_NORESULTS \"No results\")\n\t\t\t{ return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\trespond :: Response *World -> *(Response, *World)\n\t\trespond r w = (r, writeCache request r w)\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= map (uncurry (makeTypeResult (Just typeName))) types\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n (Location lib mod Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\(Location _ _ _ c`) _ _ _ -> toLowerCase c` == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult (Location lib mod line cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [(concat (print False t), map loc ls) \\\\ (t,ls) <- getInstances cls db]\n\t\t }\n\t\t )\n\twhere\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef -> Result\n\tmakeTypeResult mbName (Location lib mod line t) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,builtin) = case fl of\n\t\t\t(Location l m ln f) = (l, m, f, ln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> (String, String, Maybe Int)\n\tloc (Location lib mod ln _) = (lib, mod, ln)\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg +\n\t\t\tif (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\" + \")\\n\"\n\tmsgToString _ _ = \"\"\n","old_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , libraries :: Maybe ([String], Bool)\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , dcl_line :: Maybe Int\n , distance :: Int\n , builtin :: Maybe Bool\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , recordfield_of :: Maybe String\n , generic_derivations :: Maybe [(String, [(String,String,Maybe Int)])]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [(String, [(String,String,Maybe Int)])]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = MaybeError Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , libraries = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mr, w) = readCache request w\n\t\t| isJust mr = let m = fromJust mr in ({m & return = 1}, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_INVALIDNAME \"function name too long\", w)\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= (err E_INVALIDNAME \"name cannot contain spaces\", w)\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= (err E_INVALIDTYPE \"couldn't parse type\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err E_NORESULTS \"No results\")\n\t\t\t{ return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save cache file\n\t\t= (response, writeCache request response w)\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= map (uncurry (makeTypeResult (Just typeName))) types\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n (Location lib mod Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\(Location _ _ _ c`) _ _ _ -> toLowerCase c` == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult (Location lib mod line cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [(concat (print False t), map loc ls) \\\\ (t,ls) <- getInstances cls db]\n\t\t }\n\t\t )\n\twhere\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef -> Result\n\tmakeTypeResult mbName (Location lib mod line t) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,builtin) = case fl of\n\t\t\t(Location l m ln f) = (l, m, f, ln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> (String, String, Maybe Int)\n\tloc (Location lib mod ln _) = (lib, mod, ln)\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg +\n\t\t\tif (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\" + \")\\n\"\n\tmsgToString _ _ = \"\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"3c22dcaae43eb33dd17d655f4078bc7aee953e97","subject":"Fix run-time error with unparsable requests","message":"Fix run-time error with unparsable requests\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import o, seq\nfrom StdMisc import abort, undef\nimport StdOrdList\nimport StdOverloaded\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable, instance Foldable Maybe\nfrom Data.Func import $\nimport Data.Functor\nimport Data.List\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat), instance Text String\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\n\nStart w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2\n\t= help w\n# [_,port:_] = cmdline\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDb f\n#! db = eval_all_nodes db\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle db\n\t, logger = Just log\n\t, port = toInt port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} w\nwhere\n\thelp :: *World -> *World\n\thelp w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\teval_all_nodes :: !.a -> .a \/\/ From GraphCopy\n\teval_all_nodes g = code {\n\t\tpush_a 0\n\t\t.d 1 0\n\t\tjsr\t_eval_to_nf\n\t\t.o 0 0\n\t}\n\n\thandle :: !CloogleDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle db Nothing w = (err InvalidInput \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey key, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err InvalidName \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err InvalidName \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err InvalidType \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! results = drop drop_n $ sort $ search request db\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! suggestions = unify >>= parseType o fromString >>= flip (suggs name) db\n\t\t#! w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- 'Foldable'.concat suggestions] w\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: !Response !*World -> *(!Response, !CacheKey, !*World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !CloogleDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Maybe Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ mkTime mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ mkTime mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import o, seq\nfrom StdMisc import abort, undef\nimport StdOrdList\nimport StdOverloaded\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable, instance Foldable Maybe\nfrom Data.Func import $\nimport Data.Functor\nimport Data.List\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat), instance Text String\nimport Text.JSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, ClassOrGeneric, Type, RequestCacheKey\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: Request -> RequestCacheKey\ntoRequestCacheKey r =\n\t{ c_unify = r.unify >>= parseType o fromString\n\t, c_name = r.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromJust (r.include_builtins <|> Just DEFAULT_INCLUDE_BUILTINS)\n\t, c_include_core = fromJust (r.include_core <|> Just DEFAULT_INCLUDE_CORE)\n\t, c_page = fromJust (r.page <|> Just 0)\n\t}\n\nStart w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2\n\t= help w\n# [_,port:_] = cmdline\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDb f\n#! db = eval_all_nodes db\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle db\n\t, logger = Just log\n\t, port = toInt port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} w\nwhere\n\thelp :: *World -> *World\n\thelp w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\teval_all_nodes :: !.a -> .a \/\/ From GraphCopy\n\teval_all_nodes g = code {\n\t\tpush_a 0\n\t\t.d 1 0\n\t\tjsr\t_eval_to_nf\n\t\t.o 0 0\n\t}\n\n\thandle :: !CloogleDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle db Nothing w = (err InvalidInput \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey key, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err InvalidName \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err InvalidName \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err InvalidType \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! results = drop drop_n $ sort $ search request db\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! suggestions = unify >>= parseType o fromString >>= flip (suggs name) db\n\t\t#! w = seq [cachePages\n\t\t\t\t(toRequestCacheKey req) CACHE_PREFETCH 0 zero suggs\n\t\t\t\t\\\\ (req,suggs) <- 'Foldable'.concat suggestions] w\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\tkey = toRequestCacheKey request\n\n\t\trespond :: !Response !*World -> *(!Response, !CacheKey, !*World)\n\t\trespond r w = (r, cacheKey key, writeCache LongTerm key r w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !CloogleDB -> Maybe [(Request, [Result])]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: LogMessage` :== LogMessage (Maybe Request) Response CacheKey\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, request :: Request\n\t, cachekey :: String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received (Just r)) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response ck) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ mkTime mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ mkTime mem.mem_time_end)\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"76d97edbdb2afd9d45667597405839f301a923b5","subject":"Resolve #92: generic locations in icl","message":"Resolve #92: generic locations in icl\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/builddb.icl","new_file":"backend\/builddb.icl","new_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, ::Macro{..}, ::ModuleInfo{..},\n\tinstance zero TypeExtras, instance zero ModuleInfo\n\n\/\/ StdEnv\nfrom StdFunc import const, flip, o\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf,startsWith),\n\tinstance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String,\n\tinstance print Type, instance print Priority\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos,td_ident},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const False)\n\t , (\"CleanSerial\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"GraphCopy\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"Platform\", const False)\n\t , (\"Sapl\", const False)\n\t , (\"SoccerFun\", const False)\n\t , (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"iTasks\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putClasses predefClasses db\n\t# db = 'DB'.putTypes predefTypes db\n\t# db = 'DB'.putFunctions (flatten $ map constructor_functions predefTypes) db\n\t# db = 'DB'.putFunctions (flatten $ map record_functions predefTypes) db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = 'DB'.saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] 'DB'.TypeDB\n\t\t*DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod,iscore):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib iscore cache db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !'DB'.TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ 'DB'.moduleCount db\n\t\t\t\t, 'DB'.functionCount db\n\t\t\t\t, 'DB'.macroCount db\n\t\t\t\t, 'DB'.typeCount db\n\t\t\t\t, 'DB'.classCount db\n\t\t\t\t, 'DB'.instanceCount db\n\t\t\t\t, 'DB'.deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t , ( 'DB'.Builtin \"dynamic\"\n\t , 'DB'.ET ('T'.Func ['T'.Var \"a\"] ('T'.Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext, [('DB'.Name, 'DB'.ExtendedType)])]\npredefClasses\n\t= [ ( 'DB'.Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"_#Array\" ['T'.Type \"Char\" []]) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[], 'Type'.cons_priority=Nothing}\n\n\/\/ Exclude Root Library Check for core Base module\nfindModules :: ![String] !String !'DB'.Library ('DB'.Module -> Bool) !String !*World\n\t-> *(![('DB'.Library, 'DB'.Module, Bool)], !*World)\nfindModules ex root lib iscore base w\n| any (\\e -> indexOf e path <> -1) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s -> let mod = basedot +++ s % (0, size s - 5) in\n\t(lib, mod, iscore mod)) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (\\d -> findModules ex root lib iscore (basedot +++ d)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any (\\e -> indexOf e (path +++ \"\/\" +++ s) <> -1) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String 'DB'.Module 'DB'.Library Bool\n\t*DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib iscore cache db w\n# (Right dcl,cache,w) = readModule False cache w\n# (icl,cache,w) = readModule True cache w\n# icl = case icl of (Left _) = Nothing; (Right x) = Just x\n# mod = dcl.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putFunctions (pd_typespecs lib mod dcl.mod_defs icl) db\n# db = 'DB'.putInstances (pd_instances lib mod dcl.mod_defs icl) db\n# db = 'DB'.putClasses (pd_classes lib mod dcl.mod_defs icl) db\n# typedefs = pd_types lib mod dcl.mod_defs icl\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib mod dcl.mod_defs icl) db\n# db = 'DB'.putDerivationss (pd_derivations lib mod dcl.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib mod dcl.mod_defs) db\n# db = 'DB'.putModule lib mod {zero & is_core=iscore} db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine pos) Nothing id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= 'T'.toMaybePriority}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- dcl]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id dcl of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id dcl\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):dcl]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:dcl] = findTypeSpec id dcl\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, 'DB'.Location)])]\n\tpd_derivations lib mod dcl\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, 'DB'.Location lib mod (toLine gc_pos) Nothing \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- dcl, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType gen_type)\n\t\t {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars\n\t\t , te_representation=Just $ cpp gen}\n\t\t ) \\\\ gen=:(PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars}) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [g.gen_pos \\\\ PD_Generic g <- pms | g.gen_ident.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_typespecs :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType t)\n\t\t { zero & te_priority = 'T'.toMaybePriority p\n\t\t , te_representation = Just $ cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pos \\\\ PD_TypeSpec pos id _ _ _ <- pms | id.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_instances :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Class, ['DB'.Type], 'DB'.Location)]\n\tpd_instances lib mod dcl icl\n\t\t= [( id_name\n\t\t , map 'T'.toType pi_types\n\t\t , 'DB'.Location lib mod (toLine pi_pos) (findIclLine id_name =<< icl) \"\"\n\t\t ) \\\\ PD_Instance {pim_pi={pi_ident={id_name},pi_types,pi_pos}} <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pi_pos \\\\ PD_Instance {pim_pi={pi_pos,pi_ident}} <- pms | pi_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_classes :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod dcl icl\n\t# dcl = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) dcl\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} dcl)\n\t\t-> let\n\t\t\ttypespecs = pd_typespecs lib mod dcl icl\n\t\t\tmacros = pd_macros lib mod dcl\n\t\t\tgetMacro n = case filter ((==) n o 'DB'.getName o fst) macros of\n\t\t\t\t[] = Nothing\n\t\t\t\t[(_,m):_] = Just m.macro_as_string\n\t\t\tupdateRepresentation n ('DB'.ET t te)\n\t\t\t\t= 'DB'.ET t {te & te_representation = getMacro n <|> te.te_representation}\n\t\tin ('DB'.Location lib mod (toLine class_pos) (findIclLine id_name =<< icl) id_name\n\t\t , map 'T'.toTypeVar class_args\n\t\t , flatten $ map 'T'.toClassContext class_context\n\t\t , [(f,updateRepresentation f et) \\\\ ('DB'.Location _ _ _ _ f, et) <- typespecs])) dcl\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [class_pos \\\\ PD_Class {class_ident,class_pos} _ <- pms | class_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_types :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod dcl icl\n\t\t= [let name = 'T'.td_name td in\n\t\t\t('DB'.Location lib mod (toLine ptd.td_pos) (findIclLine name =<< icl) name, td)\n\t\t \\\\ PD_Type ptd <- dcl, td <- ['T'.toTypeDef ptd]]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [td_pos \\\\ PD_Type {td_ident,td_pos} <- pms | td_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\n\treadModule :: Bool *DclCache *World -> *(Either String ParsedModule, *DclCache, *World)\n\treadModule icl cache w\n\t# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ if icl \".icl\" \".dcl\"\n\t# (ok,f,w) = fopen filename FReadText w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n\t cache = {cache & hash_table=ht}\n\t# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" icl mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n\t cache = {cache & hash_table=ht}\n\t# (ok,w) = fclose f w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t= (Right pm, cache, w)\n\nconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nconstructor_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\nconstructor_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\n\nprint_prio :: (Maybe 'T'.Priority) -> [String]\nprint_prio Nothing = []\nprint_prio (Just p) = [\" \"] ++ print False p\n\nrecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nrecord_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\nrecord_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","old_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, ::Macro{..}, ::ModuleInfo{..},\n\tinstance zero TypeExtras, instance zero ModuleInfo\n\n\/\/ StdEnv\nfrom StdFunc import const, flip, o\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf,startsWith),\n\tinstance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String,\n\tinstance print Type, instance print Priority\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos,td_ident},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const False)\n\t , (\"CleanSerial\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"GraphCopy\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"Platform\", const False)\n\t , (\"Sapl\", const False)\n\t , (\"SoccerFun\", const False)\n\t , (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"iTasks\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putClasses predefClasses db\n\t# db = 'DB'.putTypes predefTypes db\n\t# db = 'DB'.putFunctions (flatten $ map constructor_functions predefTypes) db\n\t# db = 'DB'.putFunctions (flatten $ map record_functions predefTypes) db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = 'DB'.saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] 'DB'.TypeDB\n\t\t*DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod,iscore):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib iscore cache db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !'DB'.TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ 'DB'.moduleCount db\n\t\t\t\t, 'DB'.functionCount db\n\t\t\t\t, 'DB'.macroCount db\n\t\t\t\t, 'DB'.typeCount db\n\t\t\t\t, 'DB'.classCount db\n\t\t\t\t, 'DB'.instanceCount db\n\t\t\t\t, 'DB'.deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t , ( 'DB'.Builtin \"dynamic\"\n\t , 'DB'.ET ('T'.Func ['T'.Var \"a\"] ('T'.Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext, [('DB'.Name, 'DB'.ExtendedType)])]\npredefClasses\n\t= [ ( 'DB'.Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"_#Array\" ['T'.Type \"Char\" []]) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[], 'Type'.cons_priority=Nothing}\n\n\/\/ Exclude Root Library Check for core Base module\nfindModules :: ![String] !String !'DB'.Library ('DB'.Module -> Bool) !String !*World\n\t-> *(![('DB'.Library, 'DB'.Module, Bool)], !*World)\nfindModules ex root lib iscore base w\n| any (\\e -> indexOf e path <> -1) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s -> let mod = basedot +++ s % (0, size s - 5) in\n\t(lib, mod, iscore mod)) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (\\d -> findModules ex root lib iscore (basedot +++ d)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any (\\e -> indexOf e (path +++ \"\/\" +++ s) <> -1) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String 'DB'.Module 'DB'.Library Bool\n\t*DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib iscore cache db w\n# (Right dcl,cache,w) = readModule False cache w\n# (icl,cache,w) = readModule True cache w\n# icl = case icl of (Left _) = Nothing; (Right x) = Just x\n# mod = dcl.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putFunctions (pd_typespecs lib mod dcl.mod_defs icl) db\n# db = 'DB'.putInstances (pd_instances lib mod dcl.mod_defs icl) db\n# db = 'DB'.putClasses (pd_classes lib mod dcl.mod_defs icl) db\n# typedefs = pd_types lib mod dcl.mod_defs icl\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib mod dcl.mod_defs) db\n# db = 'DB'.putDerivationss (pd_derivations lib mod dcl.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib mod dcl.mod_defs) db\n# db = 'DB'.putModule lib mod {zero & is_core=iscore} db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine pos) Nothing id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= 'T'.toMaybePriority}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- dcl]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id dcl of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id dcl\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):dcl]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:dcl] = findTypeSpec id dcl\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, 'DB'.Location)])]\n\tpd_derivations lib mod dcl\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, 'DB'.Location lib mod (toLine gc_pos) Nothing \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- dcl, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition]\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) Nothing id_name\n\t\t , 'DB'.ET ('T'.toType gen_type)\n\t\t {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars\n\t\t , te_representation=Just $ cpp gen}\n\t\t ) \\\\ gen=:(PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars}) <- dcl]\n\n\tpd_typespecs :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType t)\n\t\t { zero & te_priority = 'T'.toMaybePriority p\n\t\t , te_representation = Just $ cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pos \\\\ PD_TypeSpec pos id _ _ _ <- pms | id.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_instances :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Class, ['DB'.Type], 'DB'.Location)]\n\tpd_instances lib mod dcl icl\n\t\t= [( id_name\n\t\t , map 'T'.toType pi_types\n\t\t , 'DB'.Location lib mod (toLine pi_pos) (findIclLine id_name =<< icl) \"\"\n\t\t ) \\\\ PD_Instance {pim_pi={pi_ident={id_name},pi_types,pi_pos}} <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pi_pos \\\\ PD_Instance {pim_pi={pi_pos,pi_ident}} <- pms | pi_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_classes :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod dcl icl\n\t# dcl = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) dcl\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} dcl)\n\t\t-> let\n\t\t\ttypespecs = pd_typespecs lib mod dcl icl\n\t\t\tmacros = pd_macros lib mod dcl\n\t\t\tgetMacro n = case filter ((==) n o 'DB'.getName o fst) macros of\n\t\t\t\t[] = Nothing\n\t\t\t\t[(_,m):_] = Just m.macro_as_string\n\t\t\tupdateRepresentation n ('DB'.ET t te)\n\t\t\t\t= 'DB'.ET t {te & te_representation = getMacro n <|> te.te_representation}\n\t\tin ('DB'.Location lib mod (toLine class_pos) (findIclLine id_name =<< icl) id_name\n\t\t , map 'T'.toTypeVar class_args\n\t\t , flatten $ map 'T'.toClassContext class_context\n\t\t , [(f,updateRepresentation f et) \\\\ ('DB'.Location _ _ _ _ f, et) <- typespecs])) dcl\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [class_pos \\\\ PD_Class {class_ident,class_pos} _ <- pms | class_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_types :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod dcl icl\n\t\t= [let name = 'T'.td_name td in\n\t\t\t('DB'.Location lib mod (toLine ptd.td_pos) (findIclLine name =<< icl) name, td)\n\t\t \\\\ PD_Type ptd <- dcl, td <- ['T'.toTypeDef ptd]]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [td_pos \\\\ PD_Type {td_ident,td_pos} <- pms | td_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\n\treadModule :: Bool *DclCache *World -> *(Either String ParsedModule, *DclCache, *World)\n\treadModule icl cache w\n\t# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ if icl \".icl\" \".dcl\"\n\t# (ok,f,w) = fopen filename FReadText w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n\t cache = {cache & hash_table=ht}\n\t# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" icl mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n\t cache = {cache & hash_table=ht}\n\t# (ok,w) = fclose f w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t= (Right pm, cache, w)\n\nconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nconstructor_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\nconstructor_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\n\nprint_prio :: (Maybe 'T'.Priority) -> [String]\nprint_prio Nothing = []\nprint_prio (Just p) = [\" \"] ++ print False p\n\nrecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nrecord_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\nrecord_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"c4a75ba9b777c64782573bf319e9d901053aad20","subject":"Use fromMaybe instead of an if in SimpleTCPServer.icl","message":"Use fromMaybe instead of an if in SimpleTCPServer.icl\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/SimpleTCPServer.icl","new_file":"backend\/SimpleTCPServer.icl","new_contents":"implementation module SimpleTCPServer\n\nimport StdEnv\nimport Data.Maybe\nimport System._Posix\nimport TCPIP\n\ninstance zero (Logger a b s t) where zero = \\_ _ w -> (undef, w)\n\nserve :: !(Server a b s t) !*World -> *World | fromString a & toString b\nserve server w\n# (ok, mbListener, w) = openTCP_Listener server.port w\n| not ok = abort (\"Couldn't open port \" +++ toString server.port +++ \"\\n\")\n# listener = fromJust mbListener\n# (_,w) = signal 17 1 w \/\/ SIGCHLD, SIG_IGN: no notification if child ps dies\n# (listener, w) = loop listener w\n= closeRChannel listener w\nwhere\n\tlogger = fromMaybe zero server.logger\n\n\tloop :: TCP_Listener *World -> (TCP_Listener, *World)\n\tloop li w\n\t#! (tRep,conn,li,w) = receive_MT server.connect_timeout li w\n\t| tRep <> TR_Success\n\t\t= (li,w)\n\t#! (ip,dupChan) = fromJust conn\n\t#! (pid,w) = fork w\n\t| pid < 0\n\t\t= abort \"fork failed\\n\"\n\t| pid > 0 \/\/ Parent: handle new requests\n\t\t= loop li w\n\t| pid == 0 \/\/ Child: handle current request\n\t\t#! (st,w) = logger (Connected ip) Nothing w\n\t\t= handle st dupChan w\n\n\t\/\/handle :: !(Maybe s) !TCP_DuplexChannel !*World -> *(!TCP_Listener, !*World)\n\thandle st dupChannel=:{rChannel,sChannel} w\n\t#! (tRep,msg,rChannel,w) = receive_MT server.keepalive_timeout rChannel w\n\t| tRep <> TR_Success\n\t\t#! (st,w) = logger Disconnected st w\n\t\t#! w = closeChannel sChannel (closeRChannel rChannel w)\n\t\t= exit 0 w\n\t#! msg = fromString (toString (fromJust msg))\n\t#! (st, w) = logger (Received msg) st w\n\t#! (resp, hidden, w) = server.handler msg w\n\t#! (sChannel, w) = send (toByteSeq (toString resp)) sChannel w\n\t#! (st, w) = logger (Sent resp hidden) st w\n\t= handle st {dupChannel & rChannel=rChannel, sChannel=sChannel} w\n\nsignal :: !Int !Int !*World -> *(!Int, !*World)\nsignal signum handler w = code {\n\tccall signal \"II:I:A\"\n}\n","old_contents":"implementation module SimpleTCPServer\n\nimport StdEnv\nimport StdMaybe\nimport System._Posix\nimport TCPIP\n\ninstance zero (Logger a b s t) where zero = \\_ _ w -> (undef, w)\n\nserve :: !(Server a b s t) !*World -> *World | fromString a & toString b\nserve server w\n# (ok, mbListener, w) = openTCP_Listener server.port w\n| not ok = abort (\"Couldn't open port \" +++ toString server.port +++ \"\\n\")\n# listener = fromJust mbListener\n# (_,w) = signal 17 1 w \/\/ SIGCHLD, SIG_IGN: no notification if child ps dies\n# (listener, w) = loop listener w\n= closeRChannel listener w\nwhere\n\tlogger = if (isNothing server.logger) zero (fromJust server.logger)\n\n\tloop :: TCP_Listener *World -> (TCP_Listener, *World)\n\tloop li w\n\t#! (tRep,conn,li,w) = receive_MT server.connect_timeout li w\n\t| tRep <> TR_Success\n\t\t= (li,w)\n\t#! (ip,dupChan) = fromJust conn\n\t#! (pid,w) = fork w\n\t| pid < 0\n\t\t= abort \"fork failed\\n\"\n\t| pid > 0 \/\/ Parent: handle new requests\n\t\t= loop li w\n\t| pid == 0 \/\/ Child: handle current request\n\t\t#! (st,w) = logger (Connected ip) Nothing w\n\t\t= handle st dupChan w\n\n\t\/\/handle :: !(Maybe s) !TCP_DuplexChannel !*World -> *(!TCP_Listener, !*World)\n\thandle st dupChannel=:{rChannel,sChannel} w\n\t#! (tRep,msg,rChannel,w) = receive_MT server.keepalive_timeout rChannel w\n\t| tRep <> TR_Success\n\t\t#! (st,w) = logger Disconnected st w\n\t\t#! w = closeChannel sChannel (closeRChannel rChannel w)\n\t\t= exit 0 w\n\t#! msg = fromString (toString (fromJust msg))\n\t#! (st, w) = logger (Received msg) st w\n\t#! (resp, hidden, w) = server.handler msg w\n\t#! (sChannel, w) = send (toByteSeq (toString resp)) sChannel w\n\t#! (st, w) = logger (Sent resp hidden) st w\n\t= handle st {dupChannel & rChannel=rChannel, sChannel=sChannel} w\n\nsignal :: !Int !Int !*World -> *(!Int, !*World)\nsignal signum handler w = code {\n\tccall signal \"II:I:A\"\n}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"c1cc1b66d2f800d8356d56daa337f3c3f636913d","subject":"Close stdOut upon termination of Bot, resolves #5","message":"Close stdOut upon termination of Bot, resolves #5\n","repos":"ErinvanderVeen\/Clone,ErinvanderVeen\/Clone","old_file":"src\/Bot.icl","new_file":"src\/Bot.icl","new_contents":"","old_contents":"","returncode":0,"stderr":"unknown","license":"mit","lang":"Clean"} {"commit":"c4a1742f7e210361324dd8199da9c2d6ab3be400","subject":"don't really need chars above 64k","message":"don't really need chars above 64k\n","repos":"rschleitzer\/scaly","old_file":"scalysh\/scaly.dcl","new_file":"scalysh\/scaly.dcl","new_contents":"\"\n PIC \"?>\"\n SHORTREF NONE\n\n NAMES\n SGMLREF\n\n QUANTITY\n NONE -- Quantities are not restricted in XML --\n\n ENTITIES\n \"amp\" 38\n \"lt\" 60\n \"gt\" 62\n \"quot\" 34\n \"apos\" 39\n\n FEATURES\n MINIMIZE\n DATATAG NO\n OMITTAG YES\n RANK NO\n SHORTTAG\n STARTTAG\n EMPTY YES\n UNCLOSED YES\n NETENABL IMMEDNET\n ENDTAG\n EMPTY YES\n UNCLOSED YES\n ATTRIB\n DEFAULT YES\n OMITNAME YES\n VALUE YES\n EMPTYNRM YES\n IMPLYDEF\n ATTLIST NO -- VALID: was YES --\n DOCTYPE NO\n ELEMENT NO -- VALID: was YES --\n ENTITY NO\n NOTATION NO -- VALID: was YES --\n LINK\n SIMPLE NO\n IMPLICIT NO\n EXPLICIT NO\n OTHER\n CONCUR NO\n SUBDOC NO\n FORMAL NO\n URN NO\n KEEPRSRE YES\n VALIDITY TYPE -- VALID: was NOASSERT --\n ENTITIES\n REF ANY\n INTEGRAL YES\n\n APPINFO NONE\n\n SEEALSO \"ISO 8879\/\/NOTATION Extensible Markup Language (XML) 1.0\/\/EN\"\n>\n\n\n","old_contents":"\"\n PIC \"?>\"\n SHORTREF NONE\n\n NAMES\n SGMLREF\n\n QUANTITY\n NONE -- Quantities are not restricted in XML --\n\n ENTITIES\n \"amp\" 38\n \"lt\" 60\n \"gt\" 62\n \"quot\" 34\n \"apos\" 39\n\n FEATURES\n MINIMIZE\n DATATAG NO\n OMITTAG YES\n RANK NO\n SHORTTAG\n STARTTAG\n EMPTY YES\n UNCLOSED YES\n NETENABL IMMEDNET\n ENDTAG\n EMPTY YES\n UNCLOSED YES\n ATTRIB\n DEFAULT YES\n OMITNAME YES\n VALUE YES\n EMPTYNRM YES\n IMPLYDEF\n ATTLIST NO -- VALID: was YES --\n DOCTYPE NO\n ELEMENT NO -- VALID: was YES --\n ENTITY NO\n NOTATION NO -- VALID: was YES --\n LINK\n SIMPLE NO\n IMPLICIT NO\n EXPLICIT NO\n OTHER\n CONCUR NO\n SUBDOC NO\n FORMAL NO\n URN NO\n KEEPRSRE YES\n VALIDITY TYPE -- VALID: was NOASSERT --\n ENTITIES\n REF ANY\n INTEGRAL YES\n\n APPINFO NONE\n\n SEEALSO \"ISO 8879\/\/NOTATION Extensible Markup Language (XML) 1.0\/\/EN\"\n>\n\n\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"60cecb97b46a640b4ae52e3776823ad9fbf222f8","subject":"Test script for VMS (eol=CR; not sure if that is necessary; native might be better)","message":"Test script for VMS \n(eol=CR; not sure if that is necessary; native might be better)\n\ngit-svn-id: a20303ca0449e3ef575223833049c5e6a53b9062@646882 13f79535-47bb-0310-9956-ffa450edef68\n","repos":"mohanaraosv\/commons-exec,apache\/commons-exec,sgoeschl\/commons-exec,sgoeschl\/commons-exec,mohanaraosv\/commons-exec,apache\/commons-exec","old_file":"src\/test\/bin\/testme.dcl","new_file":"src\/test\/bin\/testme.dcl","new_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r$!\r$! Licensed to the Apache Software Foundation (ASF) under one or more\r$! contributor license agreements. See the NOTICE file distributed with\r$! this work for additional information regarding copyright ownership.\r$! The ASF licenses this file to You under the Apache License, Version 2.0\r$! (the \"License\"); you may not use this file except in compliance with\r$! the License. You may obtain a copy of the License at\r$!\r$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\r$!\r$! Unless required by applicable law or agreed to in writing, software\r$! distributed under the License is distributed on an \"AS IS\" BASIS,\r$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r$! See the License for the specific language governing permissions and\r$! limitations under the License.\r$!\r$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r$! \r$! Run the test suite\r$!\r$ create\/directory [.target]\r$ java \"-Dorg.apache.commons.exec.lenient=false\" \"-Dorg.apache.commons.exec.debug=false\" -\r -cp \".\/lib\/junit-3.8.1.jar:.\/lib\/exec-test-1.0-SNAPSHOT.jar:.\/lib\/exec-1.0-SNAPSHOT.jar\" -\r \"org.apache.commons.exec.TestRunner\"","old_contents":"","returncode":1,"stderr":"error: pathspec 'src\/test\/bin\/testme.dcl' did not match any file(s) known to git\n","license":"apache-2.0","lang":"Clean"} {"commit":"ee4bab7cdfb3ff9ed90b7b8d4215cfec06b7e326","subject":"Fix syntax of hiding imports","message":"Fix syntax of hiding imports\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/Builtins.icl","new_file":"backend\/Builtins.icl","new_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [FunctionEntry]\nbuiltin_functions =\n\t[ { zero\n\t & fe_loc=Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []\n\t }\n\t, { zero\n\t & fe_loc=Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]\n\t }\n\t]\n\nbuiltin_classes :: [ClassEntry]\nbuiltin_classes =\n\t[ { ce_loc=Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , ce_vars=[\"v\"]\n\t , ce_is_meta=False\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t , ce_usages=[]\n\t }\n\t]\n\nbuiltin_types :: [TypeDefEntry]\nbuiltin_types =\n\t[ { deft\n\t & tde_loc=Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t, { deft & tde_loc=Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Int\"}\n\t, { deft & tde_loc=Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Real\"}\n\t, { deft & tde_loc=Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Char\"}\n\t, { deft & tde_loc=Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], tde_typedef.td_name = \"Dynamic\"}\n\t, { deft & tde_loc=Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"File\"}\n\t, { deft\n\t & tde_loc=Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"]\n\t , tde_typedef.td_name = \"String\"\n\t , tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) }\n\t, { deft\n\t & tde_loc=Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"World\"\n\t , tde_typedef.td_uniq = True\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\"\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"]\n\t , tde_typedef.td_name = \"(->)\"\n\t , tde_typedef.td_args = [Var \"a\", Var \"b\"]\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\"\n\t , vars = [\"The argument type\", \"The result type\"]\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"()\" []\n\t , tde_typedef.td_name=\"_Unit\"\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The void \/ unit type.\"\n\t }\n\t , tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]\n\t }\n\t: lists\n\t++ arrays\n\t++ tuples\n\t]\nwhere\n\tdeft =\n\t\t{ tde_loc=zero\n\t\t, tde_typedef=\n\t\t\t{ td_name=\"\"\n\t\t\t, td_uniq=False\n\t\t\t, td_args=[]\n\t\t\t, td_rhs=TDRAbstract Nothing\n\t\t\t}\n\t\t, tde_doc=Nothing\n\t\t, tde_instances=[]\n\t\t, tde_derivations=[]\n\t\t, tde_usages=[]\n\t\t}\n\tdefc =\n\t\t{ cons_name=\"\"\n\t\t, cons_args=[]\n\t\t, cons_exi_vars=[]\n\t\t, cons_context=[]\n\t\t, cons_priority=Nothing\n\t\t}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> TypeDefEntry\n\t\tmake_list k s =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the list elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> TypeDefEntry\n\t\tmake_array k =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the array elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> TypeDefEntry\n\t\tmake_tuple n =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"]\n\t\t\t, tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t\t\"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t\t\"Clean supports tuples of arity 2 to 32.\"\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [FunctionEntry]\nbuiltin_functions =\n\t[ { zero\n\t & fe_loc=Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []\n\t }\n\t, { zero\n\t & fe_loc=Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]\n\t }\n\t]\n\nbuiltin_classes :: [ClassEntry]\nbuiltin_classes =\n\t[ { ce_loc=Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , ce_vars=[\"v\"]\n\t , ce_is_meta=False\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t , ce_usages=[]\n\t }\n\t]\n\nbuiltin_types :: [TypeDefEntry]\nbuiltin_types =\n\t[ { deft\n\t & tde_loc=Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t, { deft & tde_loc=Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Int\"}\n\t, { deft & tde_loc=Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Real\"}\n\t, { deft & tde_loc=Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], tde_typedef.td_name = \"Char\"}\n\t, { deft & tde_loc=Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], tde_typedef.td_name = \"Dynamic\"}\n\t, { deft & tde_loc=Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"File\"}\n\t, { deft\n\t & tde_loc=Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"]\n\t , tde_typedef.td_name = \"String\"\n\t , tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) }\n\t, { deft\n\t & tde_loc=Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], tde_typedef.td_name = \"World\"\n\t , tde_typedef.td_uniq = True\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\"\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"]\n\t , tde_typedef.td_name = \"(->)\"\n\t , tde_typedef.td_args = [Var \"a\", Var \"b\"]\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\"\n\t , vars = [\"The argument type\", \"The result type\"]\n\t }\n\t }\n\t, { deft\n\t & tde_loc=Builtin \"()\" []\n\t , tde_typedef.td_name=\"_Unit\"\n\t , tde_doc = Just\n\t { TypeDoc | gDefault{|*|}\n\t & description = Just \"The void \/ unit type.\"\n\t }\n\t , tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]\n\t }\n\t: lists\n\t++ arrays\n\t++ tuples\n\t]\nwhere\n\tdeft =\n\t\t{ tde_loc=zero\n\t\t, tde_typedef=\n\t\t\t{ td_name=\"\"\n\t\t\t, td_uniq=False\n\t\t\t, td_args=[]\n\t\t\t, td_rhs=TDRAbstract Nothing\n\t\t\t}\n\t\t, tde_doc=Nothing\n\t\t, tde_instances=[]\n\t\t, tde_derivations=[]\n\t\t, tde_usages=[]\n\t\t}\n\tdefc =\n\t\t{ cons_name=\"\"\n\t\t, cons_args=[]\n\t\t, cons_exi_vars=[]\n\t\t, cons_context=[]\n\t\t, cons_priority=Nothing\n\t\t}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> TypeDefEntry\n\t\tmake_list k s =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the list elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> TypeDefEntry\n\t\tmake_array k =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"]\n\t\t\t, tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description\n\t\t\t\t, vars = [\"The type of the array elements.\"]\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> TypeDefEntry\n\t\tmake_tuple n =\n\t\t\t{ deft\n\t\t\t& tde_loc = Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"]\n\t\t\t, tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just\n\t\t\t\t{ TypeDoc | gDefault{|*|}\n\t\t\t\t& description = Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t\t\"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t\t\"Clean supports tuples of arity 2 to 32.\"\n\t\t\t\t}\n\t\t\t}\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... qualified => ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t, EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"Function\" \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"1f03ab7f98d6f0220d59a85921b6dc4873be8fac","subject":"Exclude Platform\/Deprecated again, as before","message":"Exclude Platform\/Deprecated again, as before\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/builddb.icl","new_file":"backend\/builddb.icl","new_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, ::Macro{..}, ::ModuleInfo{..},\n\tinstance zero TypeExtras, instance zero ModuleInfo\n\n\/\/ StdEnv\nfrom StdFunc import const, flip, o\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf,startsWith),\n\tinstance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String,\n\tinstance print Type, instance print Priority, instance == Type\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Instances,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos,td_ident},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const False)\n\t , (\"CleanPrettyPrint\", const False)\n\t , (\"CleanSerial\", const False)\n\t , (\"CleanTypeUnifier\", const False)\n\t , (\"Cloogle\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"GraphCopy\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"Platform\", const False)\n\t , (\"Sapl\", const False)\n\t , (\"SoccerFun\", const False)\n\t , (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"iTasks\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"Platform\/Deprecated\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putClasses predefClasses db\n\t# db = 'DB'.putTypes predefTypes db\n\t# db = 'DB'.putFunctions (flatten $ map constructor_functions predefTypes) db\n\t# db = 'DB'.putFunctions (flatten $ map record_functions predefTypes) db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = 'DB'.saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] 'DB'.TypeDB\n\t\t*DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod,iscore):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib iscore cache db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !'DB'.TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ 'DB'.moduleCount db\n\t\t\t\t, 'DB'.functionCount db\n\t\t\t\t, 'DB'.macroCount db\n\t\t\t\t, 'DB'.typeCount db\n\t\t\t\t, 'DB'.classCount db\n\t\t\t\t, 'DB'.instanceCount db\n\t\t\t\t, 'DB'.deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t , ( 'DB'.Builtin \"dynamic\"\n\t , 'DB'.ET ('T'.Func ['T'.Var \"a\"] ('T'.Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext, [('DB'.Name, 'DB'.ExtendedType)])]\npredefClasses\n\t= [ ( 'DB'.Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"_#Array\" ['T'.Type \"Char\" []]) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[], 'Type'.cons_priority=Nothing}\n\n\/\/ Exclude Root Library Check for core Base module\nfindModules :: ![String] !String !'DB'.Library ('DB'.Module -> Bool) !String !*World\n\t-> *(![('DB'.Library, 'DB'.Module, Bool)], !*World)\nfindModules ex root lib iscore base w\n| any (\\e -> indexOf e path <> -1) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s -> let mod = basedot +++ s % (0, size s - 5) in\n\t(lib, mod, iscore mod)) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (\\d -> findModules ex root lib iscore (basedot +++ d)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any (\\e -> indexOf e (path +++ \"\/\" +++ s) <> -1) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String 'DB'.Module 'DB'.Library Bool\n\t*DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib iscore cache db w\n# (Right dcl,cache,w) = readModule False cache w\n# (icl,cache,w) = readModule True cache w\n# icl = case icl of (Left _) = Nothing; (Right x) = Just x\n# mod = dcl.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putFunctions (pd_typespecs lib mod dcl.mod_defs icl) db\n# db = 'DB'.putInstances (pd_instances lib mod dcl.mod_defs icl) db\n# db = 'DB'.putClasses (pd_classes lib mod dcl.mod_defs icl) db\n# typedefs = pd_types lib mod dcl.mod_defs icl\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib mod dcl.mod_defs icl) db\n# db = 'DB'.putDerivationss (pd_derivations lib mod dcl.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib mod dcl.mod_defs) db\n# db = 'DB'.putModule lib mod {zero & is_core=iscore} db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine pos) Nothing id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= 'T'.toMaybePriority}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- dcl]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id dcl of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id dcl\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):dcl]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:dcl] = findTypeSpec id dcl\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, 'DB'.Location)])]\n\tpd_derivations lib mod dcl\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, 'DB'.Location lib mod (toLine gc_pos) Nothing \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- dcl, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType gen_type)\n\t\t {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars\n\t\t , te_representation=Just $ cpp gen}\n\t\t ) \\\\ gen=:(PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars}) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [g.gen_pos \\\\ PD_Generic g <- pms | g.gen_ident.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_typespecs :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType t)\n\t\t { zero & te_priority = 'T'.toMaybePriority p\n\t\t , te_representation = Just $ cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pos \\\\ PD_TypeSpec pos id _ _ _ <- pms | id.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_instances :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Class, ['DB'.Type], 'DB'.Location)]\n\tpd_instances lib mod dcl icl\n\t\t= [( id\n\t\t , types\n\t\t , 'DB'.Location lib mod (toLine pos) (findIclLine id types =<< icl) \"\"\n\t\t ) \\\\ (id,types,pos) <- instances]\n\twhere\n\t\tinstances = map (appSnd3 (map 'T'.toType)) $\n\t\t\t[(i.pi_ident.id_name, i.pi_types, i.pi_pos) \\\\ PD_Instance {pim_pi=i} <- dcl]\n\t\t\t++ [(i.pi_ident.id_name, i.pi_types, i.pi_pos) \\\\ PD_Instances pis <- dcl, {pim_pi=i} <- pis]\n\n\t\tfindIclLine :: String ['T'.Type] ParsedModule -> Maybe Int\n\t\tfindIclLine name types {mod_defs=pms}\n\t\t\t= case [pi_pos\n\t\t\t\t\t\\\\ PD_Instance {pim_pi={pi_pos,pi_ident,pi_types}} <- pms\n\t\t\t\t\t| (pi_ident.id_name == name && map 'T'.toType pi_types == types)] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_classes :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod dcl icl\n\t# dcl = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) dcl\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} dcl)\n\t\t-> let\n\t\t\ttypespecs = pd_typespecs lib mod dcl icl\n\t\t\tmacros = pd_macros lib mod dcl\n\t\t\tgetMacro n = case filter ((==) n o 'DB'.getName o fst) macros of\n\t\t\t\t[] = Nothing\n\t\t\t\t[(_,m):_] = Just m.macro_as_string\n\t\t\tupdateRepresentation n ('DB'.ET t te)\n\t\t\t\t= 'DB'.ET t {te & te_representation = getMacro n <|> te.te_representation}\n\t\tin ('DB'.Location lib mod (toLine class_pos) (findIclLine id_name =<< icl) id_name\n\t\t , map 'T'.toTypeVar class_args\n\t\t , flatten $ map 'T'.toClassContext class_context\n\t\t , [(f,updateRepresentation f et) \\\\ ('DB'.Location _ _ _ _ f, et) <- typespecs])) dcl\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [class_pos \\\\ PD_Class {class_ident,class_pos} _ <- pms | class_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_types :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod dcl icl\n\t\t= [let name = 'T'.td_name td in\n\t\t\t('DB'.Location lib mod (toLine ptd.td_pos) (findIclLine name =<< icl) name, td)\n\t\t \\\\ PD_Type ptd <- dcl, td <- ['T'.toTypeDef ptd]]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [td_pos \\\\ PD_Type {td_ident,td_pos} <- pms | td_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\n\treadModule :: Bool *DclCache *World -> *(Either String ParsedModule, *DclCache, *World)\n\treadModule icl cache w\n\t# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ if icl \".icl\" \".dcl\"\n\t# (ok,f,w) = fopen filename FReadText w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n\t cache = {cache & hash_table=ht}\n\t# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" icl mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n\t cache = {cache & hash_table=ht}\n\t# (ok,w) = fclose f w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t= (Right pm, cache, w)\n\nconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nconstructor_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\nconstructor_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\n\nprint_prio :: (Maybe 'T'.Priority) -> [String]\nprint_prio Nothing = []\nprint_prio (Just p) = [\" \"] ++ print False p\n\nrecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nrecord_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\nrecord_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","old_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}, ::Macro{..}, ::ModuleInfo{..},\n\tinstance zero TypeExtras, instance zero ModuleInfo\n\n\/\/ StdEnv\nfrom StdFunc import const, flip, o\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nimport Control.Applicative, Control.Monad\nfrom Text import class Text(concat,replaceSubString,indexOf,startsWith),\n\tinstance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String,\n\tinstance print Type, instance print Priority, instance == Type\nfrom Type import qualified ::TypeDef{..}, ::Constructor{..}\nimport CoclUtils\n\n\/\/ CleanPrettyPrint\nimport CleanPrettyPrint\n\n\/\/ frontend\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents),\n\t::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr,\n\t::Position(..), ::LineNr, ::FileName, ::FunctName,\n\t::Module{mod_ident,mod_defs},\n\t::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Instances,PD_Class,PD_Type,PD_Generic,PD_Derive,PD_Function),\n\t::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType,\n\t::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_pos,pi_types},\n\t::Type, ::ClassDef{class_ident,class_pos,class_args,class_context},\n\t::TypeVar, ::ParsedTypeDef, ::TypeDef{td_pos,td_ident},\n\t::GenericDef{gen_ident,gen_pos,gen_type,gen_vars},\n\t::GenericCaseDef{gc_type,gc_pos,gc_gcf}, ::GenericCaseFunctions(GCF), ::GCF,\n\t::FunKind(FK_Macro),\n\t::Rhs, ::ParsedExpr\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const False)\n\t , (\"CleanPrettyPrint\", const False)\n\t , (\"CleanSerial\", const False)\n\t , (\"CleanTypeUnifier\", const False)\n\t , (\"Cloogle\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"GraphCopy\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"Platform\", const False)\n\t , (\"Sapl\", const False)\n\t , (\"SoccerFun\", const False)\n\t , (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"iTasks\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop cli.root mods 'DB'.newDb cache w\n\t# db = 'DB'.putFunctions predefFunctions db\n\t# db = 'DB'.putClasses predefClasses db\n\t# db = 'DB'.putTypes predefTypes db\n\t# db = 'DB'.putFunctions (flatten $ map constructor_functions predefTypes) db\n\t# db = 'DB'.putFunctions (flatten $ map record_functions predefTypes) db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = 'DB'.saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] 'DB'.TypeDB\n\t\t*DclCache *World -> *('DB'.TypeDB, *World)\n\tloop _ [] db _ w = (db,w)\n\tloop root [(lib,mod,iscore):list] db cache w\n\t# (db, cache, w) = getModuleTypes root mod lib iscore cache db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t= loop root list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !'DB'.TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ 'DB'.moduleCount db\n\t\t\t\t, 'DB'.functionCount db\n\t\t\t\t, 'DB'.macroCount db\n\t\t\t\t, 'DB'.typeCount db\n\t\t\t\t, 'DB'.classCount db\n\t\t\t\t, 'DB'.instanceCount db\n\t\t\t\t, 'DB'.deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [('DB'.Location, 'DB'.ExtendedType)]\npredefFunctions\n\t= [ ( 'DB'.Builtin \"if\"\n\t , 'DB'.ET ('T'.Func ['T'.Type \"Bool\" [], 'T'.Var \"a\", 'T'.Var \"a\"] ('T'.Var \"a\") []) zero\n\t )\n\t , ( 'DB'.Builtin \"dynamic\"\n\t , 'DB'.ET ('T'.Func ['T'.Var \"a\"] ('T'.Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext, [('DB'.Name, 'DB'.ExtendedType)])]\npredefClasses\n\t= [ ( 'DB'.Builtin \"TC\", [\"v\"], [], [])\n\t ]\n\npredefTypes :: [('DB'.Location, 'T'.TypeDef)]\npredefTypes\n\t= [ ( 'DB'.Builtin \"Bool\"\n\t , { deft\n\t & 'Type'.td_name = \"Bool\"\n\t , 'Type'.td_rhs = 'T'.TDRCons False\n\t [ { defc & 'Type'.cons_name=\"False\" }\n\t , { defc & 'Type'.cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( 'DB'.Builtin \"Int\", { deft & 'Type'.td_name = \"Int\" } )\n\t , ( 'DB'.Builtin \"Real\", { deft & 'Type'.td_name = \"Real\" } )\n\t , ( 'DB'.Builtin \"Char\", { deft & 'Type'.td_name = \"Char\" } )\n\t , ( 'DB'.Builtin \"String\", { deft & 'Type'.td_name = \"String\",\n\t 'Type'.td_rhs = 'T'.TDRSynonym ('T'.Type \"_#Array\" ['T'.Type \"Char\" []]) } )\n\t , ( 'DB'.Builtin \"Dynamic\", { deft & 'Type'.td_name = \"Dynamic\" } )\n\t , ( 'DB'.Builtin \"File\", { deft & 'Type'.td_name = \"File\" } )\n\t , ( 'DB'.Builtin \"World\", { deft & 'Type'.td_name = \"World\",\n\t 'Type'.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {'Type'.td_name=\"\", 'Type'.td_uniq=False, 'Type'.td_args=[], 'Type'.td_rhs='T'.TDRAbstract}\n\tdefc = {'Type'.cons_name=\"\", 'Type'.cons_args=[], 'Type'.cons_exi_vars=[], 'Type'.cons_context=[], 'Type'.cons_priority=Nothing}\n\n\/\/ Exclude Root Library Check for core Base module\nfindModules :: ![String] !String !'DB'.Library ('DB'.Module -> Bool) !String !*World\n\t-> *(![('DB'.Library, 'DB'.Module, Bool)], !*World)\nfindModules ex root lib iscore base w\n| any (\\e -> indexOf e path <> -1) ex = ([], w)\n#! (fps, w) = readDirectory path w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (\\s -> let mod = basedot +++ s % (0, size s - 5) in\n\t(lib, mod, iscore mod)) $ filter included $ filter isDclModule fps\n#! (moremodss,w) = mapSt (\\d -> findModules ex root lib iscore (basedot +++ d)) (filter isDirectory fps) w\n= (removeDup (mods ++ flatten moremodss), w)\nwhere\n\tpath = root +++ \"\/\" +++ lib +++ if (base == \"\") \"\" \"\/\" +++ replaceSubString \".\" \"\/\" base\n\tbasedot = if (base == \"\") \"\" (base +++ \".\")\n\n\tincluded :: String -> Bool\n\tincluded s = not (any (\\e -> indexOf e (path +++ \"\/\" +++ s) <> -1) ex)\n\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String 'DB'.Module 'DB'.Library Bool\n\t*DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes root mod lib iscore cache db w\n# (Right dcl,cache,w) = readModule False cache w\n# (icl,cache,w) = readModule True cache w\n# icl = case icl of (Left _) = Nothing; (Right x) = Just x\n# mod = dcl.mod_ident.id_name\n# lib = cleanlib mod lib\n# db = 'DB'.putFunctions (pd_typespecs lib mod dcl.mod_defs icl) db\n# db = 'DB'.putInstances (pd_instances lib mod dcl.mod_defs icl) db\n# db = 'DB'.putClasses (pd_classes lib mod dcl.mod_defs icl) db\n# typedefs = pd_types lib mod dcl.mod_defs icl\n# db = 'DB'.putTypes typedefs db\n# db = 'DB'.putFunctions (flatten $ map constructor_functions typedefs) db\n# db = 'DB'.putFunctions (flatten $ map record_functions typedefs) db\n# db = 'DB'.putFunctions (pd_generics lib mod dcl.mod_defs icl) db\n# db = 'DB'.putDerivationss (pd_derivations lib mod dcl.mod_defs) db\n# db = 'DB'.putMacros (pd_macros lib mod dcl.mod_defs) db\n# db = 'DB'.putModule lib mod {zero & is_core=iscore} db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = { if (c == '.') '\/' c \\\\ c <-: s }\n\n\tcleanlib :: !String !String -> String \/\/ Remove module dirs from lib\n\tcleanlib mod lib = toString $ cl` (fromString $ mkdir mod) (fromString lib)\n\twhere\n\t\tcl` :: ![Char] ![Char] -> [Char]\n\t\tcl` mod lib\n\t\t\t| not (isMember '\/' mod) = lib\n\t\t\t# mod = reverse $ tl $ dropWhile ((<>)'\/') $ reverse mod\n\t\t\t| drop (length lib - length mod) lib == mod\n\t\t\t\t= take (length lib - length mod - 1) lib\n\t\t\t= lib\n\n\tpd_macros :: String String [ParsedDefinition] -> [('DB'.Location, 'DB'.Macro)]\n\tpd_macros lib mod dcl\n\t\t= [( 'DB'.Location lib mod (toLine pos) Nothing id.id_name\n\t\t , { macro_as_string = priostring id +++ cpp pd\n\t\t , macro_extras = {zero & te_priority = findPrio id >>= 'T'.toMaybePriority}\n\t\t }\n\t\t ) \\\\ pd=:(PD_Function pos id isinfix args rhs FK_Macro) <- dcl]\n\twhere\n\t\tpriostring :: Ident -> String\n\t\tpriostring id = case findTypeSpec id dcl of\n\t\t\tNothing = \"\"\n\t\t\t(Just pri) = cpp pri +++ \"\\n\"\n\n\t\tfindPrio :: Ident -> Maybe Priority\n\t\tfindPrio id = (\\(PD_TypeSpec _ _ p _ _) -> p) <$> findTypeSpec id dcl\n\n\t\tfindTypeSpec :: Ident [ParsedDefinition] -> Maybe ParsedDefinition\n\t\tfindTypeSpec _ [] = Nothing\n\t\tfindTypeSpec id [pd=:(PD_TypeSpec _ id` prio _ _):dcl]\n\t\t| id`.id_name == id.id_name = Just pd\n\t\tfindTypeSpec id [_:dcl] = findTypeSpec id dcl\n\n\tpd_derivations :: String String [ParsedDefinition]\n\t\t-> [('DB'.Name, [('DB'.Type, 'DB'.Location)])]\n\tpd_derivations lib mod dcl\n\t\t= [( id.id_name\n\t\t , [('T'.toType gc_type, 'DB'.Location lib mod (toLine gc_pos) Nothing \"\")]\n\t\t ) \\\\ PD_Derive gcdefs <- dcl, {gc_type,gc_pos,gc_gcf=GCF id _} <- gcdefs]\n\n\tpd_generics :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_generics lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine gen_pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType gen_type)\n\t\t {zero & te_generic_vars=Just $ map 'T'.toTypeVar gen_vars\n\t\t , te_representation=Just $ cpp gen}\n\t\t ) \\\\ gen=:(PD_Generic {gen_ident={id_name},gen_pos,gen_type,gen_vars}) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [g.gen_pos \\\\ PD_Generic g <- pms | g.gen_ident.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_typespecs :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.ExtendedType)]\n\tpd_typespecs lib mod dcl icl\n\t\t= [( 'DB'.Location lib mod (toLine pos) (findIclLine id_name =<< icl) id_name\n\t\t , 'DB'.ET ('T'.toType t)\n\t\t { zero & te_priority = 'T'.toMaybePriority p\n\t\t , te_representation = Just $ cpp ts}\n\t\t ) \\\\ ts=:(PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs) <- dcl]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [pos \\\\ PD_TypeSpec pos id _ _ _ <- pms | id.id_name == name] of\n\t\t\t\t[FunPos _ l _:_] = Just l\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_instances :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Class, ['DB'.Type], 'DB'.Location)]\n\tpd_instances lib mod dcl icl\n\t\t= [( id\n\t\t , types\n\t\t , 'DB'.Location lib mod (toLine pos) (findIclLine id types =<< icl) \"\"\n\t\t ) \\\\ (id,types,pos) <- instances]\n\twhere\n\t\tinstances = map (appSnd3 (map 'T'.toType)) $\n\t\t\t[(i.pi_ident.id_name, i.pi_types, i.pi_pos) \\\\ PD_Instance {pim_pi=i} <- dcl]\n\t\t\t++ [(i.pi_ident.id_name, i.pi_types, i.pi_pos) \\\\ PD_Instances pis <- dcl, {pim_pi=i} <- pis]\n\n\t\tfindIclLine :: String ['T'.Type] ParsedModule -> Maybe Int\n\t\tfindIclLine name types {mod_defs=pms}\n\t\t\t= case [pi_pos\n\t\t\t\t\t\\\\ PD_Instance {pim_pi={pi_pos,pi_ident,pi_types}} <- pms\n\t\t\t\t\t| (pi_ident.id_name == name && map 'T'.toType pi_types == types)] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_classes :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, ['T'.TypeVar], 'T'.ClassContext,\n\t\t\t[('DB'.Name, 'DB'.ExtendedType)])]\n\tpd_classes lib mod dcl icl\n\t# dcl = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) dcl\n\t= map (\\(PD_Class {class_ident={id_name},class_pos,class_args,class_context} dcl)\n\t\t-> let\n\t\t\ttypespecs = pd_typespecs lib mod dcl icl\n\t\t\tmacros = pd_macros lib mod dcl\n\t\t\tgetMacro n = case filter ((==) n o 'DB'.getName o fst) macros of\n\t\t\t\t[] = Nothing\n\t\t\t\t[(_,m):_] = Just m.macro_as_string\n\t\t\tupdateRepresentation n ('DB'.ET t te)\n\t\t\t\t= 'DB'.ET t {te & te_representation = getMacro n <|> te.te_representation}\n\t\tin ('DB'.Location lib mod (toLine class_pos) (findIclLine id_name =<< icl) id_name\n\t\t , map 'T'.toTypeVar class_args\n\t\t , flatten $ map 'T'.toClassContext class_context\n\t\t , [(f,updateRepresentation f et) \\\\ ('DB'.Location _ _ _ _ f, et) <- typespecs])) dcl\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [class_pos \\\\ PD_Class {class_ident,class_pos} _ <- pms | class_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\tpd_types :: String String [ParsedDefinition] (Maybe ParsedModule)\n\t\t-> [('DB'.Location, 'DB'.TypeDef)]\n\tpd_types lib mod dcl icl\n\t\t= [let name = 'T'.td_name td in\n\t\t\t('DB'.Location lib mod (toLine ptd.td_pos) (findIclLine name =<< icl) name, td)\n\t\t \\\\ PD_Type ptd <- dcl, td <- ['T'.toTypeDef ptd]]\n\twhere\n\t\tfindIclLine :: String ParsedModule -> Maybe Int\n\t\tfindIclLine name {mod_defs=pms}\n\t\t\t= case [td_pos \\\\ PD_Type {td_ident,td_pos} <- pms | td_ident.id_name == name] of\n\t\t\t\t[LinePos _ l:_] = Just l\n\t\t\t\t_ = Nothing\n\n\ttoLine :: Position -> 'DB'.LineNr\n\ttoLine (FunPos _ l _) = Just l\n\ttoLine (LinePos _ l) = Just l\n\ttoLine _ = Nothing\n\n\treadModule :: Bool *DclCache *World -> *(Either String ParsedModule, *DclCache, *World)\n\treadModule icl cache w\n\t# filename = root +++ \"\/\" +++ lib +++ \"\/\" +++ mkdir mod +++ if icl \".icl\" \".dcl\"\n\t# (ok,f,w) = fopen filename FReadText w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n\t cache = {cache & hash_table=ht}\n\t# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" icl mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n\t cache = {cache & hash_table=ht}\n\t# (ok,w) = fclose f w\n\t| not ok = (Left $ \"Couldn't open \" +++ filename, cache, w)\n\t= (Right pm, cache, w)\n\nconstructor_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nconstructor_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\nconstructor_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline c, 'DB'.ET f\n\t\t{zero & te_isconstructor=True\n\t\t , te_representation=Just $ concat $\n\t\t [c] ++ print_prio p ++ [\" :: \"] ++ print False f\n\t\t , te_priority=p})\n\t \\\\ (c,f,p) <- 'T'.constructorsToFunctions td]\n\nprint_prio :: (Maybe 'T'.Priority) -> [String]\nprint_prio Nothing = []\nprint_prio (Just p) = [\" \"] ++ print False p\n\nrecord_functions :: ('DB'.Location, 'DB'.TypeDef)\n\t-> [('DB'.Location, 'DB'.ExtendedType)]\nrecord_functions ('DB'.Builtin _, td)\n\t= [('DB'.Builtin f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\nrecord_functions ('DB'.Location lib mod line iclline _, td)\n\t= [('DB'.Location lib mod line iclline f, 'DB'.ET t\n\t\t{zero & te_isrecordfield=True\n\t\t , te_representation=Just $ concat $ [\".\", f, \" :: \" : print False t]})\n\t\t\\\\ (f,t) <- 'T'.recordsToFunctions td]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"da5e6a02d9158a3c413c0f1e06fc172787fa264d","subject":"Cache more aggressively","message":"Cache more aggressively\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat,toLowerCase), instance Text String, <+\nimport Text.GenJSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\nCACHE_NS_THRESHOLD :== 20000000\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Maybe [String]\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (alwaysUnique,db) = alwaysUniquePredicate db\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True alwaysUnique allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.Request.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> unprepare <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\nwhere\n\tunprepare :: !Type -> Type\n\tunprepare (Type t ts) = Type t (map unprepare ts)\n\tunprepare (Func is t tc) = Func (map unprepare is) (unprepare t) (map unprepareTR tc)\n\tunprepare (Var tv) = Var (tv % (1,size tv-1))\n\tunprepare (Cons v ts) = Cons (v % (1,size v-1)) (map unprepare ts)\n\tunprepare (Uniq t) = Uniq (unprepare t)\n\tunprepare (Forall ts t tc) = Forall (map unprepare ts) (unprepare t) (map unprepareTR tc)\n\tunprepare (Arrow mt) = Arrow (unprepare <$> mt)\n\n\tunprepareTR :: !TypeRestriction -> TypeRestriction\n\tunprepareTR (Instance c ts) = Instance c (map unprepare ts)\n\tunprepareTR (Derivation g t) = Derivation g (unprepare t)\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w)\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", (Nothing,0), db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t#! (start,w) = nsTime w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond start Nothing {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond start Nothing (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond start Nothing (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond start Nothing (err InvalidType \"Couldn't parse type\") db w\n\t\t| all isNothing [unify,name,request.typeName,request.className] && isNothing request.using\n\t\t\t= respond start Nothing (err InvalidInput \"Empty query\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond start (Just key) response db w\n\twhere\n\t\trespond :: !Timespec !(Maybe RequestCacheKey) !Response !*CloogleDB !*World ->\n\t\t\t*(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\t\trespond start key r db w\n\t\t#! (end,w) = nsTime w\n\t\t#! duration = 1000000000 * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec\n\t\t#! cache = duration > CACHE_NS_THRESHOLD\n\t\t= (r, (if cache (cacheKey <$> key) Nothing, duration \/ 1000), db, case (cache,key) of\n\t\t\t(True,Just k) -> writeCache LongTerm k r w\n\t\t\t_ -> w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World)\n\treloadCache (db,w)\n\t# (ks,w) = allCacheKeys LongTerm w\n\t= loop ks db w\n\twhere\n\t\tloop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World)\n\t\tloop [] db w = (db,w)\n\t\tloop [k:ks] db w\n\t\t# w = removeFromCache LongTerm k w\n\t\t# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w\n\t\t# db = resetDB db\n\t\t= loop ks db w\n\n\tdoInBackground :: (*a -> *a) *a -> *a\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: MicroSeconds :== Int\n\n:: LogMessage` :== LogMessage (Maybe Request) Response (Maybe CacheKey, MicroSeconds)\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, microseconds :: Int\n\t, request :: Maybe Request\n\t, cachekey :: Maybe String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response (ck,us)) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, microseconds = us\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","old_contents":"module CloogleServer\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import id, o\nimport StdList\nimport StdMisc\nimport StdOrdList\nimport StdOverloaded\nimport StdString\nimport StdTuple\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Error\nimport qualified Data.Foldable as Foldable\nfrom Data.Foldable import class Foldable\nfrom Data.Func import $, hyperstrict, instance Functor ((->) r), mapSt, seqSt\nimport Data.Functor\nfrom Data.List import permutations\nimport Data.Maybe\nimport Data.Tuple\nimport System._Posix\nimport System.CommandLine\nimport System.Time\nfrom Text import class Text(concat,toLowerCase), instance Text String, <+\nimport Text.GenJSON\n\nimport Cloogle\nimport Type\nimport CloogleDB\nimport Search\n\nimport SimpleTCPServer\nimport Cache\nimport Memory\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\nCACHE_NS_THRESHOLD :== 40000000\n\n:: RequestCacheKey\n\t= { c_unify :: Maybe Type\n\t , c_name :: Maybe String\n\t , c_className :: Maybe String\n\t , c_typeName :: Maybe String\n\t , c_using :: Maybe [String]\n\t , c_modules :: Maybe [String]\n\t , c_libraries :: Maybe [String]\n\t , c_include_builtins :: Bool\n\t , c_include_core :: Bool\n\t , c_include_apps :: Bool\n\t , c_page :: Int\n\t }\n\nderive JSONEncode Kind, Type, RequestCacheKey, TypeRestriction\nderive JSONDecode Kind, Type, RequestCacheKey, TypeRestriction\ninstance toString RequestCacheKey\nwhere toString rck = toString $ toJSON rck\n\ntoRequestCacheKey :: !*CloogleDB !Request -> *(!RequestCacheKey, !*CloogleDB)\ntoRequestCacheKey db r\n# (alwaysUnique,db) = alwaysUniquePredicate db\n# (allsyns,db) = allTypeSynonyms db\n= (\n\t{ c_unify = snd <$>\n\t\tprepare_unification True alwaysUnique allsyns <$>\n\t\t(parseType o fromString =<< r.unify)\n\t, c_name = toLowerCase <$> r.Request.name\n\t, c_className = r.className\n\t, c_typeName = r.typeName\n\t, c_using = r.using\n\t, c_modules = sort <$> r.modules\n\t, c_libraries = sort <$> r.libraries\n\t, c_include_builtins = fromMaybe DEFAULT_INCLUDE_BUILTINS r.include_builtins\n\t, c_include_core = fromMaybe DEFAULT_INCLUDE_CORE r.include_core\n\t, c_include_apps = fromMaybe DEFAULT_INCLUDE_APPS r.include_apps\n\t, c_page = fromMaybe 0 r.page\n\t}, db)\nfromRequestCacheKey :: RequestCacheKey -> Request\nfromRequestCacheKey k =\n\t{ unify = concat <$> print False <$> unprepare <$> k.c_unify\n\t, name = k.c_name\n\t, className = k.c_className\n\t, typeName = k.c_typeName\n\t, using = k.c_using\n\t, modules = k.c_modules\n\t, libraries = k.c_libraries\n\t, include_builtins = Just k.c_include_builtins\n\t, include_core = Just k.c_include_core\n\t, include_apps = Just k.c_include_apps\n\t, page = Just k.c_page\n\t}\nwhere\n\tunprepare :: !Type -> Type\n\tunprepare (Type t ts) = Type t (map unprepare ts)\n\tunprepare (Func is t tc) = Func (map unprepare is) (unprepare t) (map unprepareTR tc)\n\tunprepare (Var tv) = Var (tv % (1,size tv-1))\n\tunprepare (Cons v ts) = Cons (v % (1,size v-1)) (map unprepare ts)\n\tunprepare (Uniq t) = Uniq (unprepare t)\n\tunprepare (Forall ts t tc) = Forall (map unprepare ts) (unprepare t) (map unprepareTR tc)\n\tunprepare (Arrow mt) = Arrow (unprepare <$> mt)\n\n\tunprepareTR :: !TypeRestriction -> TypeRestriction\n\tunprepareTR (Instance c ts) = Instance c (map unprepare ts)\n\tunprepareTR (Derivation g t) = Derivation g (unprepare t)\n\n:: Options =\n\t{ port :: Int\n\t, help :: Bool\n\t, reload_cache :: Bool\n\t}\n\ninstance zero Options where zero = {port=31215, help=False, reload_cache=False}\n\nparseOptions :: Options [String] -> MaybeErrorString Options\nparseOptions opt [] = Ok opt\nparseOptions opt [\"-p\":p:rest] = case (toInt p, p) of\n\t(0, \"0\") -> Error \"Cannot use port 0\"\n\t(0, p) -> Error $ \"'\" <+ p <+ \"' is not an integer\"\n\t(p, _) -> parseOptions {Options | opt & port=p} rest\nparseOptions opt [\"-h\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--help\":rest] = parseOptions {opt & help=True} rest\nparseOptions opt [\"--reload-cache\":rest] = parseOptions {opt & reload_cache=True} rest\nparseOptions opt [arg:_] = Error $ \"Unknown option '\" <+ arg <+ \"'\"\n\nStart w\n# (cmdline, w) = getCommandLine w\n# opts = parseOptions zero (tl cmdline)\n| isError opts\n\t# (io,w) = stdio w\n\t# io = io <<< fromError opts <<< \"\\n\"\n\t# (_,w) = fclose io w\n\t= w\n# opts = fromOk opts\n| opts.help = help (hd cmdline) w\n# w = disableSwap w\n#! (_,f,w) = fopen \"types.json\" FReadText w\n#! (db,f) = openDB f\n#! (ok,db) = isJustU db\n| not ok\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not open database\\n\"\n\t# (_,w) = fclose io w\n\t= w\n#! db = hyperstrict (fromJust db)\n#! (db,w) = if opts.reload_cache (doInBackground reloadCache) id (db,w)\n#! (_,w) = fclose f w\n= serve\n\t{ handler = handle\n\t, logger = Just log\n\t, port = opts.Options.port\n\t, connect_timeout = Just 3600000 \/\/ 1h\n\t, keepalive_timeout = Just 5000 \/\/ 5s\n\t} db w\nwhere\n\thelp :: String *World -> *World\n\thelp pgm w\n\t# (io, w) = stdio w\n\t# io = io <<< \"Usage: \" <<< pgm <<< \" [--reload-cache] [-p ] [-h] [--help]\\n\"\n\t= snd $ fclose io w\n\n\tdisableSwap :: *World -> *World\n\tdisableSwap w\n\t# (ok,w) = mlockall (MCL_CURRENT bitor MCL_FUTURE) w\n\t| ok = w\n\t# (err,w) = errno w\n\t# (io,w) = stdio w\n\t# io = io <<< \"Could not lock memory (\" <<< err <<< \"); process may get swapped out\\n\"\n\t= snd $ fclose io w\n\n\thandle :: !(Maybe Request) !*CloogleDB !*World -> *(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\thandle Nothing db w = (err InvalidInput \"Couldn't parse input\", (Nothing,0), db, w)\n\thandle (Just request=:{unify,name,page}) db w\n\t\t#! (start,w) = nsTime w\n\t\t\/\/Check cache\n\t\t#! (key,db) = toRequestCacheKey db request\n\t\t#! (mbResponse, w) = readCache key w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= respond start Nothing {r & return = if (r.return == 0) 1 r.return} db w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond start Nothing (err InvalidName \"Function name too long\") db w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond start Nothing (err InvalidName \"Name cannot contain spaces\") db w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond start Nothing (err InvalidType \"Couldn't parse type\") db w\n\t\t| all isNothing [unify,name,request.typeName,request.className] && isNothing request.using\n\t\t\t= respond start Nothing (err InvalidInput \"Empty query\") db w\n\t\t\/\/ Results\n\t\t#! drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t#! (res,db) = search request db\n\t\t#! results = drop drop_n res\n\t\t#! more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t#! (suggestions,db) = case unify >>= parseType o fromString of\n\t\t\tJust t -> suggs name t db\n\t\t\tNothing -> (Nothing, db)\n\t\t#! (db,w) = seqSt\n\t\t\t(\\(req,res) (db,w) -> let (k,db`) = toRequestCacheKey db req in (db`,cachePages k CACHE_PREFETCH 0 zero res w))\n\t\t\t(fromMaybe [] suggestions)\n\t\t\t(db,w)\n\t\t#! suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<) (length results) o snd) <$>\n\t\t\t map (appSnd length) <$> suggestions\n\t\t#! (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t#! response = if (isEmpty results)\n\t\t\t(err NoResults \"No results\")\n\t\t\t{ zero\n\t\t & data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t#! w = cachePages key CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond start (Just key) response db w\n\twhere\n\t\trespond :: !Timespec !(Maybe RequestCacheKey) !Response !*CloogleDB !*World ->\n\t\t\t*(!Response, !(!Maybe CacheKey, !MicroSeconds), !*CloogleDB, !*World)\n\t\trespond start key r db w\n\t\t#! (end,w) = nsTime w\n\t\t#! duration = 1000000000 * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec\n\t\t#! cache = duration > CACHE_NS_THRESHOLD\n\t\t= (r, (if cache (cacheKey <$> key) Nothing, duration \/ 1000), db, case (cache,key) of\n\t\t\t(True,Just k) -> writeCache LongTerm k r w\n\t\t\t_ -> w)\n\n\t\tcachePages :: !RequestCacheKey !Int !Int !Response ![Result] !*World -> *World\n\t\tcachePages key _ _ _ [] w = w\n\t\tcachePages key 0 _ _ _ w = w\n\t\tcachePages key npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages key (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { key & c_page = key.c_page + i }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !*CloogleDB -> *(Maybe [(Request, [Result])], *CloogleDB)\n\tsuggs n (Func is r cc) db | length is < 3\n\t= appFst Just $ mapSt (\\r -> appFst (tuple r) o search r o resetDB) reqs db\n\twhere\n\t\treqs = [{zero & name=n, unify=Just $ concat $ print False $ Func is` r cc}\n\t\t\t\\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ db = (Nothing, db)\n\n\treloadCache :: !*(!*CloogleDB, !*World) -> *(!*CloogleDB, !*World)\n\treloadCache (db,w)\n\t# (ks,w) = allCacheKeys LongTerm w\n\t= loop ks db w\n\twhere\n\t\tloop :: ![RequestCacheKey] !*CloogleDB !*World -> *(!*CloogleDB, !*World)\n\t\tloop [] db w = (db,w)\n\t\tloop [k:ks] db w\n\t\t# w = removeFromCache LongTerm k w\n\t\t# (_,_,db,w) = handle (Just $ fromRequestCacheKey k) db w\n\t\t# db = resetDB db\n\t\t= loop ks db w\n\n\tdoInBackground :: (*a -> *a) *a -> *a\n\tdoInBackground f w\n\t#! (pid,w) = fork w\n\t| pid < 0 = abort \"fork failed\\n\"\n\t| pid > 0 = w \/\/ Parent: return directly\n\t| pid == 0 = snd $ exit 0 $ f w \/\/ Child: do function\n\n:: LogMemory =\n\t{ mem_ip :: IPAddress\n\t, mem_time_start :: Tm\n\t, mem_time_end :: Tm\n\t, mem_request :: Maybe Request\n\t}\n\ninstance zero LogMemory\nwhere\n\tzero =\n\t\t{ mem_ip = undef\n\t\t, mem_time_start = undef\n\t\t, mem_time_end = undef\n\t\t, mem_request = undef\n\t\t}\n\n:: MicroSeconds :== Int\n\n:: LogMessage` :== LogMessage (Maybe Request) Response (Maybe CacheKey, MicroSeconds)\n\n:: LogEntry =\n\t{ ip :: String\n\t, time_start :: (String, Int)\n\t, time_end :: (String, Int)\n\t, microseconds :: Int\n\t, request :: Maybe Request\n\t, cachekey :: Maybe String\n\t, response_code :: Int\n\t, results :: Int\n\t}\n\nderive JSONEncode LogEntry\n\nlog :: LogMessage` (Maybe LogMemory) *World -> *(Maybe LogMemory, *World)\nlog msg mem w\n# mem = fromJust (mem <|> pure zero)\n# (mem,w) = updateMemory msg mem w\n| not needslog = (Just mem, w)\n# (io,w) = stdio w\n# io = io <<< toString (toJSON $ makeLogEntry msg mem) <<< \"\\n\"\n= (Just mem, snd (fclose io w))\nwhere\n\tneedslog = case msg of (Sent _ _) = True; _ = False\n\n\tupdateMemory :: LogMessage` LogMemory *World -> *(LogMemory, *World)\n\tupdateMemory (Connected ip) s w = ({s & mem_ip=ip}, w)\n\tupdateMemory (Received r) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_start=t, mem_request=r}, w)\n\tupdateMemory (Sent _ _) s w\n\t# (t,w) = localTime w\n\t= ({s & mem_time_end=t}, w)\n\tupdateMemory _ s w = (s,w)\n\n\tmakeLogEntry :: LogMessage` LogMemory -> LogEntry\n\tmakeLogEntry (Sent response (ck,us)) mem =\n\t\t{ ip = toString mem.mem_ip\n\t\t, time_start = (toString mem.mem_time_start, toInt $ timeGm mem.mem_time_start)\n\t\t, time_end = (toString mem.mem_time_end, toInt $ timeGm mem.mem_time_end)\n\t\t, microseconds = us\n\t\t, request = mem.mem_request\n\t\t, cachekey = ck\n\t\t, response_code = response.return\n\t\t, results = length response.data\n\t\t}\n\nerr :: CloogleError String -> Response\nerr c m = { return = toInt c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"31e47fe11bdd1b35302d807cb42681e6160cf3e4","subject":"Add some ABC documentation","message":"Add some ABC documentation\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle","old_file":"backend\/BuiltinABCInstructions.icl","new_file":"backend\/BuiltinABCInstructions.icl","new_contents":"implementation module BuiltinABCInstructions\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle\n\nimport CloogleDB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \"- sep can be either `-` or `:`.\"\n\t\t\t, \"- flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \"- input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t\t, \"- output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t\t, \"- state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \"- `I` for integers\"\n\t\t\t, \"- `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \"- [`Rr`] for reals\"\n\t\t\t, \"- `S` for Clean Strings (`{#Char}`).\"\n\t\t\t, \"- `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}})\"\n\t\t\t, \"- `A` for A-stack elements (e.g. used for `*World`, a boxed integer under the hood)\"\n\t\t\t, \"- [`OF`] for function pointers\"\n\t\t\t, \"- `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_o\n\t, d_export\n\t, d_module\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the name of the module.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildAC\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_array\"\n\t, \"create_array_\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eqAC_a\"\n\t, \"eq_desc\"\n\t, \"eq_desc_b\"\n\t, \"eq_nulldesc\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_a_b\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_t_r_a\"\n\t, \"push_t_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_t\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".depend\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".inline\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".n\"\n\t, \".nu\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","old_contents":"implementation module BuiltinABCInstructions\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle\n\nimport CloogleDB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t pushes ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\npushes :: [ABCInstructionEntry]\npushes =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \"- sep can be either `-` or `:`.\"\n\t\t\t, \"- flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \"- input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t\t, \"- output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t\t, \"- state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \"- `I` for integers\"\n\t\t\t, \"- `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \"- [`Rr`] for reals\"\n\t\t\t, \"- `S` for Clean Strings (`{#Char}`).\"\n\t\t\t, \"- `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}})\"\n\t\t\t, \"- `A` for A-stack elements (e.g. used for `*World`, a boxed integer under the hood)\"\n\t\t\t, \"- [`OF`] for function pointers\"\n\t\t\t, \"- `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_o\n\t, d_export\n\t, d_module\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the name of the module.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildAC\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_array\"\n\t, \"create_array_\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eqAC_a\"\n\t, \"eq_desc\"\n\t, \"eq_desc_b\"\n\t, \"eq_nulldesc\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"get_node_arity\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"pop_a\"\n\t, \"pop_b\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_a\"\n\t, \"push_b\"\n\t, \"push_a_b\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_t_r_a\"\n\t, \"push_t_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_t\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".depend\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".inline\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".n\"\n\t, \".nu\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"a7d6a92bc84d9b769c50106d2353012861b05a85","subject":"Fix hostname parsing for cloaked hostnames","message":"Fix hostname parsing for cloaked hostnames\n","repos":"clean-cloogle\/clean-irc","old_file":"IRC.icl","new_file":"IRC.icl","new_contents":"implementation module IRC\n\nimport StdList, StdTuple, StdOverloaded, StdFunc, StdString, StdChar, StdBool\nimport _SystemArray\n\nimport GenPrint\nimport GenIRC\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Either\nimport Data.Maybe\nimport Data.Tuple\nimport Text.Parsers.Simple.Chars\nimport Text.Parsers.Simple.Core\n\nimport StdDebug\n\nfrom Data.Functor import <$>\nfrom Data.Func import $\nfrom StdMisc import undef, abort\nfrom Text import class Text(lpad,trim,rtrim,split,indexOf,concat),\n\tinstance Text String\nimport qualified Text\n\njon :== 'Text'.join\n\nderive gPrint IRCErrors, IRCReplies, Maybe, Either, IRCUser, IRCNumReply\n\nStart = (map (fmap toString) msgs, msgs)\nwhere\n\tmsgs =\n\t\t[ parseIRCMessage \":clooglebot!~cloogle@dhcp-077-249-221-037.chello.nl QUIT\\r\\n\"\n\t\t, parseIRCMessage \":clooglebot!~cloogle QUIT\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 QUIT\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY test\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY :test with spaces\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net NOTICE * :*** Found your hostname\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net QUIT :hoi hoi\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net JOIN #cha,#ch-b #twilight\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net ISON a b c d e f :g h\\r\\n\"\n\t\t, parseIRCMessage \":wilhelm.freenode.net 001 clooglebot :Welcome to the freenode Internet Relay Chat Network clooglebot\\r\\n\"\n\t\t, parseIRCMessage \"PING :orwell.freenode.net\\r\\n\"\n\t\t, parseIRCMessage \":ChanServ!ChanServ@services. MODE #cloogle +o frobnicator\\r\\n\"\n\t\t]\n\nparseIRCMessage :: String -> Either [Error] IRCMessage\nparseIRCMessage s = case runParser parsePrefix (fromString s) of\n\t\/\/ Prefix is parsed\n\t([(prefix, rest):_], _)\n\t\t\/\/Try parsing a numeric reply\n\t\t= case parse parseReply rest of\n\t\t\t\/\/Try a normal command\n\t\t\tLeft e = case parseCmd rest of\n\t\t\t\tLeft e2 = Left [e2:e]\n\t\t\t\tRight cmd = Right {IRCMessage | irc_prefix=prefix, irc_command=Right cmd}\n\t\t\tRight repl = Right {IRCMessage | irc_prefix=prefix, irc_command=Left repl}\n\t\/\/ Error parsing prefix\n\t(_, es) = Left [\"Error parsing prefix\"]\n\n\/\/Prefix\nparsePrefix :: Parser Char (Maybe (Either IRCUser String))\nparsePrefix\n\t= optional (pToken ':' >>| parseEither parseUser parseHost <* pToken ' ')\nwhere\n\tparseEither :: (Parser a b) (Parser a c) -> Parser a (Either b c)\n\tparseEither p q = Left <$> p <|> Right <$> q\n\n\tparseUser :: Parser Char IRCUser\n\tparseUser = parseNick\n\t\t\t>>= \\nick->optional (pToken '!' >>| parseUsr)\n\t\t\t>>= \\muser->optional (pToken '@' >>| parseHost)\n\t\t\t>>= \\mhost->pure {IRCUser\n\t\t\t\t| irc_nick=nick, irc_user=muser, irc_host=mhost}\n\t\n\tparseUsr :: Parser Char String\n\tparseUsr = toString <$> pSome (pNoneOf [' ', '@':illegal])\n\t\n\tparseNick :: Parser Char String\n\tparseNick = pAlpha \n\t\t>>= \\c ->pMany (pAlpha <|> pDigit <|> pOneOf (fromString \"-[]\\\\`^{}\"))\n\t\t>>= \\cs->pure (toString [c:cs])\n\n\tparseHost :: Parser Char String\n\tparseHost = jon \".\" <$> (pSepBy parseName (pToken '.'))\n\t\t>>= \\s->optional (pToken '.') >>= pure o maybe s (\\p->s+++toString s)\n\t\twhere\n\t\t\tparseName :: Parser Char String\n\t\t\tparseName = toString <$> pSome (pAlpha <|> pDigit <|> pOneOf ['-', '\/'])\n\n\/\/Parse Cmd\nparseCmd :: [Char] -> Either Error IRCCommand\nparseCmd cs = fst $ gIRCParse{|*|} $ argfun $ split \" \" $ toString cs\n\twhere\n\t\targfun :: [String] -> [String]\n\t\targfun [] = []\n\t\targfun [x:xs]\n\t\t# x = trim x\n\t\t| x.[0] == ':' = [jon \" \" $ [x % (1, size x):map rtrim xs]]\n\t\t| otherwise = [x:argfun xs]\n\n\/\/Reply\n\nparseReply :: Parser Char IRCNumReply\nparseReply = spaceParser\n\t>>| (pMany (pToken '0') >>| pSome pDigit <* spaceParser)\n\t>>= \\rep->(toString <$> pSome (pNoneOf [' ':illegal]) <* spaceParser)\n\t>>= \\rec->(toString <$> pSome (pNoneOf illegal))\n\t>>= \\msg->pure {IRCNumReply\n\t\t| irc_reply = fromInt $ toInt $ toString rep\n\t\t, irc_recipient = rec\n\t\t, irc_message = msg % (if (msg.[0] == ':') 1 0, size msg)\n\t\t}\n\t<* pToken '\\r' <* pToken '\\n'\n\twhere\n\t\tspaceParser :: Parser Char [Char]\n\t\tspaceParser = pMany $ pToken ' '\n\n\/\/Common parsers\npNoneOf :: [a] -> Parser a a | Eq a\npNoneOf l = pSatisfy (not o flip isMember l)\n\nillegal :: [Char]\nillegal = ['\\x00','\\r','\\n']\n\ninstance toString IRCNumReply where\n\ttoString m = lpad (toString $ toInt m.irc_reply) 3 '0' <+ \" \" <+\n\t\tm.irc_recipient <+ \" \" <+ concat (gIRCPrint{|*|} m.irc_message)\ninstance toString IRCMessage where\n\ttoString m = maybe \"\" (\\s->either ((<+) \":\") id s <+ \" \") m.irc_prefix\n\t\t<+ either toString toString m.irc_command\ninstance toString IRCUser where\n\ttoString m = m.irc_nick <+ maybe \"\" ((<+) \"!\") m.irc_user\n\t\t<+ maybe \"\" ((<+) \"@\") m.irc_host\ninstance toString IRCCommand where\n\ttoString m = jon \" \" (gIRCPrint{|*|} m) +++ \"\\r\\n\"\ninstance toString IRCReplies where toString r = printToString r\ninstance toString IRCErrors where toString r = printToString r\n\n(<+) infixr 5 :: a b -> String | toString a & toString b\n(<+) a b = toString a +++ toString b\n\ninstance fromInt IRCReplies where\n\tfromInt r = case r of \n\t\t1 = RPL_WELCOME; 2 = RPL_YOURHOST;\n\t\t3 = RPL_CREATED; 4 = RPL_MYINFO;\n\t\t5 = RPL_BOUNCE; 200 = RPL_TRACELINK;\n\t\t201 = RPL_TRACECONNECTING; 202 = RPL_TRACEHANDSHAKE;\n\t\t203 = RPL_TRACEUNKNOWN; 204 = RPL_TRACEOPERATOR;\n\t\t205 = RPL_TRACEUSER; 206 = RPL_TRACESERVER;\n\t\t207 = RPL_TRACESERVICE; 208 = RPL_TRACENEWTYPE;\n\t\t209 = RPL_TRACECLASS; 210 = RPL_TRACERECONNECT;\n\t\t211 = RPL_STATSLINKINFO; 212 = RPL_STATSCOMMANDS;\n\t\t219 = RPL_ENDOFSTATS; 221 = RPL_UMODEIS;\n\t\t234 = RPL_SERVLIST; 235 = RPL_SERVLISTEND;\n\t\t242 = RPL_STATSUPTIME; 243 = RPL_STATSOLINE;\n\t\t251 = RPL_LUSERCLIENT; 252 = RPL_LUSEROP;\n\t\t253 = RPL_LUSERUNKNOWN; 254 = RPL_LUSERCHANNELS;\n\t\t255 = RPL_LUSERME; 256 = RPL_ADMINME;\n\t\t257 = RPL_ADMINLOC1; 258 = RPL_ADMINLOC2;\n\t\t259 = RPL_ADMINEMAIL; 261 = RPL_TRACELOG;\n\t\t262 = RPL_TRACEEND; 263 = RPL_TRYAGAIN;\n\t\t301 = RPL_AWAY; 302 = RPL_USERHOST;\n\t\t303 = RPL_ISON; 304 = RPL_UNAWAY;\n\t\t305 = RPL_NOWAWAY; 311 = RPL_WHOISUSER;\n\t\t312 = RPL_WHOISSERVER; 313 = RPL_WHOISOPERATOR;\n\t\t314 = RPL_WHOWASUSER; 315 = RPL_ENDOFWHO;\n\t\t317 = RPL_WHOISIDLE; 318 = RPL_ENDOFWHOIS;\n\t\t319 = RPL_WHOISCHANNELS; 321 = RPL_LISTSTART;\n\t\t322 = RPL_LIST; 323 = RPL_LISTEND;\n\t\t324 = RPL_CHANNELMODEIS; 325 = RPL_UNIQOPIS;\n\t\t331 = RPL_NOTOPIC; 332 = RPL_TOPIC;\n\t\t341 = RPL_INVITING; 342 = RPL_SUMMONING;\n\t\t346 = RPL_INVITELIST; 347 = RPL_ENDOFINVITELIST;\n\t\t348 = RPL_EXCEPTLIST; 349 = RPL_ENDOFEXCEPTLIST;\n\t\t351 = RPL_VERSION; 352 = RPL_WHOREPLY;\n\t\t353 = RPL_NAMREPLY; 364 = RPL_LINKS;\n\t\t365 = RPL_ENDOFLINKS; 366 = RPL_ENDOFNAMES;\n\t\t367 = RPL_BANLIST; 368 = RPL_ENDOFBANLIST;\n\t\t369 = RPL_ENDOFWHOWAS; 371 = RPL_INFO;\n\t\t372 = RPL_MOTD; 374 = RPL_ENDOFINFO;\n\t\t375 = RPL_MOTDSTART; 376 = RPL_ENDOFMOTD;\n\t\t381 = RPL_YOUREOPER; 382 = RPL_REHASHING;\n\t\t383 = RPL_YOURESERVICE; 391 = RPL_TIME;\n\t\t392 = RPL_USERSSTART; 393 = RPL_USERS;\n\t\t394 = RPL_ENDOFUSERS; 395 = RPL_NOUSERS;\n\t\t_ = abort $ \"fromInt IRCReplies: \" +++ toString r +++ \" undef\\n\"\n\ninstance toInt IRCReplies where\n\ttoInt r = case r of \n\t\tRPL_WELCOME = 1; RPL_YOURHOST = 2;\n\t\tRPL_CREATED = 3; RPL_MYINFO = 4;\n\t\tRPL_BOUNCE = 5; RPL_TRACELINK = 200;\n\t\tRPL_TRACECONNECTING = 201; RPL_TRACEHANDSHAKE = 202;\n\t\tRPL_TRACEUNKNOWN = 203; RPL_TRACEOPERATOR = 204;\n\t\tRPL_TRACEUSER = 205; RPL_TRACESERVER = 206;\n\t\tRPL_TRACESERVICE = 207; RPL_TRACENEWTYPE = 208;\n\t\tRPL_TRACECLASS = 209; RPL_TRACERECONNECT = 210;\n\t\tRPL_STATSLINKINFO = 211; RPL_STATSCOMMANDS = 212;\n\t\tRPL_ENDOFSTATS = 219; RPL_UMODEIS = 221;\n\t\tRPL_SERVLIST = 234; RPL_SERVLISTEND = 234;\n\t\tRPL_STATSUPTIME = 242; RPL_STATSOLINE = 243;\n\t\tRPL_LUSERCLIENT = 251; RPL_LUSEROP = 252;\n\t\tRPL_LUSERUNKNOWN = 253; RPL_LUSERCHANNELS = 254;\n\t\tRPL_LUSERME = 255; RPL_ADMINME = 256;\n\t\tRPL_ADMINLOC1 = 257; RPL_ADMINLOC2 = 258;\n\t\tRPL_ADMINEMAIL = 259; RPL_TRACELOG = 261;\n\t\tRPL_TRACEEND = 262; RPL_TRYAGAIN = 263;\n\t\tRPL_AWAY = 301; RPL_USERHOST = 302;\n\t\tRPL_ISON = 303; RPL_UNAWAY = 304;\n\t\tRPL_NOWAWAY = 305; RPL_WHOISUSER = 311;\n\t\tRPL_WHOISSERVER = 312; RPL_WHOISOPERATOR = 313;\n\t\tRPL_WHOWASUSER = 314; RPL_ENDOFWHO = 315;\n\t\tRPL_WHOISIDLE = 317; RPL_ENDOFWHOIS = 318;\n\t\tRPL_WHOISCHANNELS = 319; RPL_LISTSTART = 321;\n\t\tRPL_LIST = 322; RPL_LISTEND = 323;\n\t\tRPL_CHANNELMODEIS = 324; RPL_UNIQOPIS = 325;\n\t\tRPL_NOTOPIC = 331; RPL_TOPIC = 332;\n\t\tRPL_INVITING = 341; RPL_SUMMONING = 342;\n\t\tRPL_INVITELIST = 346; RPL_ENDOFINVITELIST = 347;\n\t\tRPL_EXCEPTLIST = 348; RPL_ENDOFEXCEPTLIST = 349;\n\t\tRPL_VERSION = 351; RPL_WHOREPLY = 352;\n\t\tRPL_NAMREPLY = 353; RPL_LINKS = 364;\n\t\tRPL_ENDOFLINKS = 365; RPL_ENDOFNAMES = 366;\n\t\tRPL_BANLIST = 367; RPL_ENDOFBANLIST = 367;\n\t\tRPL_ENDOFWHOWAS = 369; RPL_INFO = 371;\n\t\tRPL_MOTD = 372; RPL_ENDOFINFO = 374;\n\t\tRPL_MOTDSTART = 375; RPL_ENDOFMOTD = 376;\n\t\tRPL_YOUREOPER = 381; RPL_REHASHING = 382;\n\t\tRPL_YOURESERVICE = 383; RPL_TIME = 391;\n\t\tRPL_USERSSTART = 392; RPL_USERS = 393;\n\t\tRPL_ENDOFUSERS = 394; RPL_NOUSERS = 395;\n\ninstance fromInt IRCErrors where\n\tfromInt r = case r of\n\t\t401 = ERR_NOSUCHNICK; 402 = ERR_NOSUCHSERVER;\n\t\t403 = ERR_NOSUCHCHANNEL; 404 = ERR_CANNOTSENDTOCHAN;\n\t\t405 = ERR_TOOMANYCHANNELS; 406 = ERR_WASNOSUCHNICK;\n\t\t407 = ERR_TOOMANYTARGETS; 408 = ERR_NOSUCHSERVICE;\n\t\t409 = ERR_NOORIGIN; 411 = ERR_NORECIPIENT;\n\t\t412 = ERR_NOTEXTTOSEND; 413 = ERR_NOTOPLEVEL;\n\t\t414 = ERR_WILDTOPLEVEL; 415 = ERR_BADMASK;\n\t\t421 = ERR_UNKNOWNCOMMAND; 422 = ERR_NOMOTD;\n\t\t423 = ERR_NOADMININFO; 424 = ERR_FILEERROR;\n\t\t431 = ERR_NONICKNAMEGIVEN; 432 = ERR_ERRONEUSNICKNAME;\n\t\t433 = ERR_NICKNAMEINUSE; 436 = ERR_NICKCOLLISION;\n\t\t437 = ERR_UNAVAILRESOURCE; 441 = ERR_USERNOTINCHANNEL;\n\t\t442 = ERR_NOTONCHANNEL; 443 = ERR_USERONCHANNEL;\n\t\t444 = ERR_NOLOGIN; 445 = ERR_SUMMONDISABLED;\n\t\t446 = ERR_USERSDISABLED; 451 = ERR_NOTREGISTERED;\n\t\t461 = ERR_NEEDMOREPARAMS; 462 = ERR_ALREADYREGISTRED;\n\t\t463 = ERR_NOPERMFORHOST; 464 = ERR_PASSWDMISMATCH;\n\t\t465 = ERR_YOUREBANNEDCREEP; 466 = ERR_YOUWILLBEBANNED;\n\t\t467 = ERR_KEYSET; 471 = ERR_CHANNELISFULL;\n\t\t472 = ERR_UNKNOWNMODE; 473 = ERR_INVITEONLYCHAN;\n\t\t474 = ERR_BANNEDFROMCHAN; 475 = ERR_BADCHANNELKEY;\n\t\t476 = ERR_BADCHANMASK; 477 = ERR_NOCHANMODES;\n\t\t478 = ERR_BANLISTFULL; 481 = ERR_NOPRIVILEGES;\n\t\t482 = ERR_CHANOPRIVSNEEDED; 483 = ERR_CANTKILLSERVER;\n\t\t484 = ERR_RESTRICTED; 485 = ERR_UNIQOPPRIVSNEEDED;\n\t\t491 = ERR_NOOPERHOST; 501 = ERR_UMODEUNKNOWNFLAG;\n\t\t502 = ERR_USERSDONTMATCH;\n\ninstance toInt IRCErrors where\n\ttoInt r = case r of\n\t\tERR_NOSUCHNICK = 401; ERR_NOSUCHSERVER = 402;\n\t\tERR_NOSUCHCHANNEL = 403; ERR_CANNOTSENDTOCHAN = 404;\n\t\tERR_TOOMANYCHANNELS = 405; ERR_WASNOSUCHNICK = 406;\n\t\tERR_TOOMANYTARGETS = 407; ERR_NOSUCHSERVICE = 408;\n\t\tERR_NOORIGIN = 409; ERR_NORECIPIENT = 411;\n\t\tERR_NOTEXTTOSEND = 412; ERR_NOTOPLEVEL = 413;\n\t\tERR_WILDTOPLEVEL = 414; ERR_BADMASK = 415;\n\t\tERR_UNKNOWNCOMMAND = 421; ERR_NOMOTD = 422;\n\t\tERR_NOADMININFO = 423; ERR_FILEERROR = 424;\n\t\tERR_NONICKNAMEGIVEN = 431; ERR_ERRONEUSNICKNAME = 432;\n\t\tERR_NICKNAMEINUSE = 433; ERR_NICKCOLLISION = 436;\n\t\tERR_UNAVAILRESOURCE = 437; ERR_USERNOTINCHANNEL = 441;\n\t\tERR_NOTONCHANNEL = 442; ERR_USERONCHANNEL = 443;\n\t\tERR_NOLOGIN = 444; ERR_SUMMONDISABLED = 445;\n\t\tERR_USERSDISABLED = 446; ERR_NOTREGISTERED = 451;\n\t\tERR_NEEDMOREPARAMS = 461; ERR_ALREADYREGISTRED = 462;\n\t\tERR_NOPERMFORHOST = 463; ERR_PASSWDMISMATCH = 464;\n\t\tERR_YOUREBANNEDCREEP = 465; ERR_YOUWILLBEBANNED = 466;\n\t\tERR_KEYSET = 467; ERR_CHANNELISFULL = 471;\n\t\tERR_UNKNOWNMODE = 472; ERR_INVITEONLYCHAN = 473;\n\t\tERR_BANNEDFROMCHAN = 474; ERR_BADCHANNELKEY = 475;\n\t\tERR_BADCHANMASK = 476; ERR_NOCHANMODES = 477;\n\t\tERR_BANLISTFULL = 478; ERR_NOPRIVILEGES = 481;\n\t\tERR_CHANOPRIVSNEEDED = 482; ERR_CANTKILLSERVER = 483;\n\t\tERR_RESTRICTED = 484; ERR_UNIQOPPRIVSNEEDED = 485;\n\t\tERR_NOOPERHOST = 491; ERR_UMODEUNKNOWNFLAG = 501;\n\t\tERR_USERSDONTMATCH = 502;\n","old_contents":"implementation module IRC\n\nimport StdList, StdTuple, StdOverloaded, StdFunc, StdString, StdChar, StdBool\nimport _SystemArray\n\nimport GenPrint\nimport GenIRC\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.Either\nimport Data.Maybe\nimport Data.Tuple\nimport Text.Parsers.Simple.Chars\nimport Text.Parsers.Simple.Core\n\nimport StdDebug\n\nfrom Data.Functor import <$>\nfrom Data.Func import $\nfrom StdMisc import undef, abort\nfrom Text import class Text(lpad,trim,rtrim,split,indexOf,concat),\n\tinstance Text String\nimport qualified Text\n\njon :== 'Text'.join\n\nderive gPrint IRCErrors, IRCReplies, Maybe, Either, IRCUser, IRCNumReply\n\nStart = (map (fmap toString) msgs, msgs)\nwhere\n\tmsgs =\n\t\t[ parseIRCMessage \":clooglebot!~cloogle@dhcp-077-249-221-037.chello.nl QUIT\\r\\n\"\n\t\t, parseIRCMessage \":clooglebot!~cloogle QUIT\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 QUIT\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY test\\r\\n\"\n\t\t, parseIRCMessage \":frobnicator!~frobnicat@92.110.128.124 AWAY :test with spaces\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net NOTICE * :*** Found your hostname\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net QUIT :hoi hoi\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net JOIN #cha,#ch-b #twilight\\r\\n\"\n\t\t, parseIRCMessage \":cherryh.freenode.net ISON a b c d e f :g h\\r\\n\"\n\t\t, parseIRCMessage \":wilhelm.freenode.net 001 clooglebot :Welcome to the freenode Internet Relay Chat Network clooglebot\\r\\n\"\n\t\t, parseIRCMessage \"PING :orwell.freenode.net\\r\\n\"\n\t\t, parseIRCMessage \":ChanServ!ChanServ@services. MODE #cloogle +o frobnicator\\r\\n\"\n\t\t]\n\nparseIRCMessage :: String -> Either [Error] IRCMessage\nparseIRCMessage s = case runParser parsePrefix (fromString s) of\n\t\/\/ Prefix is parsed\n\t([(prefix, rest):_], _)\n\t\t\/\/Try parsing a numeric reply\n\t\t= case parse parseReply rest of\n\t\t\t\/\/Try a normal command\n\t\t\tLeft e = case parseCmd rest of\n\t\t\t\tLeft e2 = Left [e2:e]\n\t\t\t\tRight cmd = Right {IRCMessage | irc_prefix=prefix, irc_command=Right cmd}\n\t\t\tRight repl = Right {IRCMessage | irc_prefix=prefix, irc_command=Left repl}\n\t\/\/ Error parsing prefix\n\t(_, es) = Left [\"Error parsing prefix\"]\n\n\/\/Prefix\nparsePrefix :: Parser Char (Maybe (Either IRCUser String))\nparsePrefix\n\t= optional (pToken ':' >>| parseEither parseUser parseHost <* pToken ' ')\nwhere\n\tparseEither :: (Parser a b) (Parser a c) -> Parser a (Either b c)\n\tparseEither p q = Left <$> p <|> Right <$> q\n\n\tparseUser :: Parser Char IRCUser\n\tparseUser = parseNick\n\t\t\t>>= \\nick->optional (pToken '!' >>| parseUsr)\n\t\t\t>>= \\muser->optional (pToken '@' >>| parseHost)\n\t\t\t>>= \\mhost->pure {IRCUser\n\t\t\t\t| irc_nick=nick, irc_user=muser, irc_host=mhost}\n\t\n\tparseUsr :: Parser Char String\n\tparseUsr = toString <$> pSome (pNoneOf [' ', '@':illegal])\n\t\n\tparseNick :: Parser Char String\n\tparseNick = pAlpha \n\t\t>>= \\c ->pMany (pAlpha <|> pDigit <|> pOneOf (fromString \"-[]\\\\`^{}\"))\n\t\t>>= \\cs->pure (toString [c:cs])\n\n\tparseHost :: Parser Char String\n\tparseHost = jon \".\" <$> (pSepBy parseName (pToken '.'))\n\t\t>>= \\s->optional (pToken '.') >>= pure o maybe s (\\p->s+++toString s)\n\t\twhere\n\t\t\tparseName :: Parser Char String\n\t\t\tparseName = toString <$> pSome (pAlpha <|> pDigit <|> pOneOf ['-'])\n\n\/\/Parse Cmd\nparseCmd :: [Char] -> Either Error IRCCommand\nparseCmd cs = fst $ gIRCParse{|*|} $ argfun $ split \" \" $ toString cs\n\twhere\n\t\targfun :: [String] -> [String]\n\t\targfun [] = []\n\t\targfun [x:xs]\n\t\t# x = trim x\n\t\t| x.[0] == ':' = [jon \" \" $ [x % (1, size x):map rtrim xs]]\n\t\t| otherwise = [x:argfun xs]\n\n\/\/Reply\n\nparseReply :: Parser Char IRCNumReply\nparseReply = spaceParser\n\t>>| (pMany (pToken '0') >>| pSome pDigit <* spaceParser)\n\t>>= \\rep->(toString <$> pSome (pNoneOf [' ':illegal]) <* spaceParser)\n\t>>= \\rec->(toString <$> pSome (pNoneOf illegal))\n\t>>= \\msg->pure {IRCNumReply\n\t\t| irc_reply = fromInt $ toInt $ toString rep\n\t\t, irc_recipient = rec\n\t\t, irc_message = msg % (if (msg.[0] == ':') 1 0, size msg)\n\t\t}\n\t<* pToken '\\r' <* pToken '\\n'\n\twhere\n\t\tspaceParser :: Parser Char [Char]\n\t\tspaceParser = pMany $ pToken ' '\n\n\/\/Common parsers\npNoneOf :: [a] -> Parser a a | Eq a\npNoneOf l = pSatisfy (not o flip isMember l)\n\nillegal :: [Char]\nillegal = ['\\x00','\\r','\\n']\n\ninstance toString IRCNumReply where\n\ttoString m = lpad (toString $ toInt m.irc_reply) 3 '0' <+ \" \" <+\n\t\tm.irc_recipient <+ \" \" <+ concat (gIRCPrint{|*|} m.irc_message)\ninstance toString IRCMessage where\n\ttoString m = maybe \"\" (\\s->either ((<+) \":\") id s <+ \" \") m.irc_prefix\n\t\t<+ either toString toString m.irc_command\ninstance toString IRCUser where\n\ttoString m = m.irc_nick <+ maybe \"\" ((<+) \"!\") m.irc_user\n\t\t<+ maybe \"\" ((<+) \"@\") m.irc_host\ninstance toString IRCCommand where\n\ttoString m = jon \" \" (gIRCPrint{|*|} m) +++ \"\\r\\n\"\ninstance toString IRCReplies where toString r = printToString r\ninstance toString IRCErrors where toString r = printToString r\n\n(<+) infixr 5 :: a b -> String | toString a & toString b\n(<+) a b = toString a +++ toString b\n\ninstance fromInt IRCReplies where\n\tfromInt r = case r of \n\t\t1 = RPL_WELCOME; 2 = RPL_YOURHOST;\n\t\t3 = RPL_CREATED; 4 = RPL_MYINFO;\n\t\t5 = RPL_BOUNCE; 200 = RPL_TRACELINK;\n\t\t201 = RPL_TRACECONNECTING; 202 = RPL_TRACEHANDSHAKE;\n\t\t203 = RPL_TRACEUNKNOWN; 204 = RPL_TRACEOPERATOR;\n\t\t205 = RPL_TRACEUSER; 206 = RPL_TRACESERVER;\n\t\t207 = RPL_TRACESERVICE; 208 = RPL_TRACENEWTYPE;\n\t\t209 = RPL_TRACECLASS; 210 = RPL_TRACERECONNECT;\n\t\t211 = RPL_STATSLINKINFO; 212 = RPL_STATSCOMMANDS;\n\t\t219 = RPL_ENDOFSTATS; 221 = RPL_UMODEIS;\n\t\t234 = RPL_SERVLIST; 235 = RPL_SERVLISTEND;\n\t\t242 = RPL_STATSUPTIME; 243 = RPL_STATSOLINE;\n\t\t251 = RPL_LUSERCLIENT; 252 = RPL_LUSEROP;\n\t\t253 = RPL_LUSERUNKNOWN; 254 = RPL_LUSERCHANNELS;\n\t\t255 = RPL_LUSERME; 256 = RPL_ADMINME;\n\t\t257 = RPL_ADMINLOC1; 258 = RPL_ADMINLOC2;\n\t\t259 = RPL_ADMINEMAIL; 261 = RPL_TRACELOG;\n\t\t262 = RPL_TRACEEND; 263 = RPL_TRYAGAIN;\n\t\t301 = RPL_AWAY; 302 = RPL_USERHOST;\n\t\t303 = RPL_ISON; 304 = RPL_UNAWAY;\n\t\t305 = RPL_NOWAWAY; 311 = RPL_WHOISUSER;\n\t\t312 = RPL_WHOISSERVER; 313 = RPL_WHOISOPERATOR;\n\t\t314 = RPL_WHOWASUSER; 315 = RPL_ENDOFWHO;\n\t\t317 = RPL_WHOISIDLE; 318 = RPL_ENDOFWHOIS;\n\t\t319 = RPL_WHOISCHANNELS; 321 = RPL_LISTSTART;\n\t\t322 = RPL_LIST; 323 = RPL_LISTEND;\n\t\t324 = RPL_CHANNELMODEIS; 325 = RPL_UNIQOPIS;\n\t\t331 = RPL_NOTOPIC; 332 = RPL_TOPIC;\n\t\t341 = RPL_INVITING; 342 = RPL_SUMMONING;\n\t\t346 = RPL_INVITELIST; 347 = RPL_ENDOFINVITELIST;\n\t\t348 = RPL_EXCEPTLIST; 349 = RPL_ENDOFEXCEPTLIST;\n\t\t351 = RPL_VERSION; 352 = RPL_WHOREPLY;\n\t\t353 = RPL_NAMREPLY; 364 = RPL_LINKS;\n\t\t365 = RPL_ENDOFLINKS; 366 = RPL_ENDOFNAMES;\n\t\t367 = RPL_BANLIST; 368 = RPL_ENDOFBANLIST;\n\t\t369 = RPL_ENDOFWHOWAS; 371 = RPL_INFO;\n\t\t372 = RPL_MOTD; 374 = RPL_ENDOFINFO;\n\t\t375 = RPL_MOTDSTART; 376 = RPL_ENDOFMOTD;\n\t\t381 = RPL_YOUREOPER; 382 = RPL_REHASHING;\n\t\t383 = RPL_YOURESERVICE; 391 = RPL_TIME;\n\t\t392 = RPL_USERSSTART; 393 = RPL_USERS;\n\t\t394 = RPL_ENDOFUSERS; 395 = RPL_NOUSERS;\n\t\t_ = abort $ \"fromInt IRCReplies: \" +++ toString r +++ \" undef\\n\"\n\ninstance toInt IRCReplies where\n\ttoInt r = case r of \n\t\tRPL_WELCOME = 1; RPL_YOURHOST = 2;\n\t\tRPL_CREATED = 3; RPL_MYINFO = 4;\n\t\tRPL_BOUNCE = 5; RPL_TRACELINK = 200;\n\t\tRPL_TRACECONNECTING = 201; RPL_TRACEHANDSHAKE = 202;\n\t\tRPL_TRACEUNKNOWN = 203; RPL_TRACEOPERATOR = 204;\n\t\tRPL_TRACEUSER = 205; RPL_TRACESERVER = 206;\n\t\tRPL_TRACESERVICE = 207; RPL_TRACENEWTYPE = 208;\n\t\tRPL_TRACECLASS = 209; RPL_TRACERECONNECT = 210;\n\t\tRPL_STATSLINKINFO = 211; RPL_STATSCOMMANDS = 212;\n\t\tRPL_ENDOFSTATS = 219; RPL_UMODEIS = 221;\n\t\tRPL_SERVLIST = 234; RPL_SERVLISTEND = 234;\n\t\tRPL_STATSUPTIME = 242; RPL_STATSOLINE = 243;\n\t\tRPL_LUSERCLIENT = 251; RPL_LUSEROP = 252;\n\t\tRPL_LUSERUNKNOWN = 253; RPL_LUSERCHANNELS = 254;\n\t\tRPL_LUSERME = 255; RPL_ADMINME = 256;\n\t\tRPL_ADMINLOC1 = 257; RPL_ADMINLOC2 = 258;\n\t\tRPL_ADMINEMAIL = 259; RPL_TRACELOG = 261;\n\t\tRPL_TRACEEND = 262; RPL_TRYAGAIN = 263;\n\t\tRPL_AWAY = 301; RPL_USERHOST = 302;\n\t\tRPL_ISON = 303; RPL_UNAWAY = 304;\n\t\tRPL_NOWAWAY = 305; RPL_WHOISUSER = 311;\n\t\tRPL_WHOISSERVER = 312; RPL_WHOISOPERATOR = 313;\n\t\tRPL_WHOWASUSER = 314; RPL_ENDOFWHO = 315;\n\t\tRPL_WHOISIDLE = 317; RPL_ENDOFWHOIS = 318;\n\t\tRPL_WHOISCHANNELS = 319; RPL_LISTSTART = 321;\n\t\tRPL_LIST = 322; RPL_LISTEND = 323;\n\t\tRPL_CHANNELMODEIS = 324; RPL_UNIQOPIS = 325;\n\t\tRPL_NOTOPIC = 331; RPL_TOPIC = 332;\n\t\tRPL_INVITING = 341; RPL_SUMMONING = 342;\n\t\tRPL_INVITELIST = 346; RPL_ENDOFINVITELIST = 347;\n\t\tRPL_EXCEPTLIST = 348; RPL_ENDOFEXCEPTLIST = 349;\n\t\tRPL_VERSION = 351; RPL_WHOREPLY = 352;\n\t\tRPL_NAMREPLY = 353; RPL_LINKS = 364;\n\t\tRPL_ENDOFLINKS = 365; RPL_ENDOFNAMES = 366;\n\t\tRPL_BANLIST = 367; RPL_ENDOFBANLIST = 367;\n\t\tRPL_ENDOFWHOWAS = 369; RPL_INFO = 371;\n\t\tRPL_MOTD = 372; RPL_ENDOFINFO = 374;\n\t\tRPL_MOTDSTART = 375; RPL_ENDOFMOTD = 376;\n\t\tRPL_YOUREOPER = 381; RPL_REHASHING = 382;\n\t\tRPL_YOURESERVICE = 383; RPL_TIME = 391;\n\t\tRPL_USERSSTART = 392; RPL_USERS = 393;\n\t\tRPL_ENDOFUSERS = 394; RPL_NOUSERS = 395;\n\ninstance fromInt IRCErrors where\n\tfromInt r = case r of\n\t\t401 = ERR_NOSUCHNICK; 402 = ERR_NOSUCHSERVER;\n\t\t403 = ERR_NOSUCHCHANNEL; 404 = ERR_CANNOTSENDTOCHAN;\n\t\t405 = ERR_TOOMANYCHANNELS; 406 = ERR_WASNOSUCHNICK;\n\t\t407 = ERR_TOOMANYTARGETS; 408 = ERR_NOSUCHSERVICE;\n\t\t409 = ERR_NOORIGIN; 411 = ERR_NORECIPIENT;\n\t\t412 = ERR_NOTEXTTOSEND; 413 = ERR_NOTOPLEVEL;\n\t\t414 = ERR_WILDTOPLEVEL; 415 = ERR_BADMASK;\n\t\t421 = ERR_UNKNOWNCOMMAND; 422 = ERR_NOMOTD;\n\t\t423 = ERR_NOADMININFO; 424 = ERR_FILEERROR;\n\t\t431 = ERR_NONICKNAMEGIVEN; 432 = ERR_ERRONEUSNICKNAME;\n\t\t433 = ERR_NICKNAMEINUSE; 436 = ERR_NICKCOLLISION;\n\t\t437 = ERR_UNAVAILRESOURCE; 441 = ERR_USERNOTINCHANNEL;\n\t\t442 = ERR_NOTONCHANNEL; 443 = ERR_USERONCHANNEL;\n\t\t444 = ERR_NOLOGIN; 445 = ERR_SUMMONDISABLED;\n\t\t446 = ERR_USERSDISABLED; 451 = ERR_NOTREGISTERED;\n\t\t461 = ERR_NEEDMOREPARAMS; 462 = ERR_ALREADYREGISTRED;\n\t\t463 = ERR_NOPERMFORHOST; 464 = ERR_PASSWDMISMATCH;\n\t\t465 = ERR_YOUREBANNEDCREEP; 466 = ERR_YOUWILLBEBANNED;\n\t\t467 = ERR_KEYSET; 471 = ERR_CHANNELISFULL;\n\t\t472 = ERR_UNKNOWNMODE; 473 = ERR_INVITEONLYCHAN;\n\t\t474 = ERR_BANNEDFROMCHAN; 475 = ERR_BADCHANNELKEY;\n\t\t476 = ERR_BADCHANMASK; 477 = ERR_NOCHANMODES;\n\t\t478 = ERR_BANLISTFULL; 481 = ERR_NOPRIVILEGES;\n\t\t482 = ERR_CHANOPRIVSNEEDED; 483 = ERR_CANTKILLSERVER;\n\t\t484 = ERR_RESTRICTED; 485 = ERR_UNIQOPPRIVSNEEDED;\n\t\t491 = ERR_NOOPERHOST; 501 = ERR_UMODEUNKNOWNFLAG;\n\t\t502 = ERR_USERSDONTMATCH;\n\ninstance toInt IRCErrors where\n\ttoInt r = case r of\n\t\tERR_NOSUCHNICK = 401; ERR_NOSUCHSERVER = 402;\n\t\tERR_NOSUCHCHANNEL = 403; ERR_CANNOTSENDTOCHAN = 404;\n\t\tERR_TOOMANYCHANNELS = 405; ERR_WASNOSUCHNICK = 406;\n\t\tERR_TOOMANYTARGETS = 407; ERR_NOSUCHSERVICE = 408;\n\t\tERR_NOORIGIN = 409; ERR_NORECIPIENT = 411;\n\t\tERR_NOTEXTTOSEND = 412; ERR_NOTOPLEVEL = 413;\n\t\tERR_WILDTOPLEVEL = 414; ERR_BADMASK = 415;\n\t\tERR_UNKNOWNCOMMAND = 421; ERR_NOMOTD = 422;\n\t\tERR_NOADMININFO = 423; ERR_FILEERROR = 424;\n\t\tERR_NONICKNAMEGIVEN = 431; ERR_ERRONEUSNICKNAME = 432;\n\t\tERR_NICKNAMEINUSE = 433; ERR_NICKCOLLISION = 436;\n\t\tERR_UNAVAILRESOURCE = 437; ERR_USERNOTINCHANNEL = 441;\n\t\tERR_NOTONCHANNEL = 442; ERR_USERONCHANNEL = 443;\n\t\tERR_NOLOGIN = 444; ERR_SUMMONDISABLED = 445;\n\t\tERR_USERSDISABLED = 446; ERR_NOTREGISTERED = 451;\n\t\tERR_NEEDMOREPARAMS = 461; ERR_ALREADYREGISTRED = 462;\n\t\tERR_NOPERMFORHOST = 463; ERR_PASSWDMISMATCH = 464;\n\t\tERR_YOUREBANNEDCREEP = 465; ERR_YOUWILLBEBANNED = 466;\n\t\tERR_KEYSET = 467; ERR_CHANNELISFULL = 471;\n\t\tERR_UNKNOWNMODE = 472; ERR_INVITEONLYCHAN = 473;\n\t\tERR_BANNEDFROMCHAN = 474; ERR_BADCHANNELKEY = 475;\n\t\tERR_BADCHANMASK = 476; ERR_NOCHANMODES = 477;\n\t\tERR_BANLISTFULL = 478; ERR_NOPRIVILEGES = 481;\n\t\tERR_CHANOPRIVSNEEDED = 482; ERR_CANTKILLSERVER = 483;\n\t\tERR_RESTRICTED = 484; ERR_UNIQOPPRIVSNEEDED = 485;\n\t\tERR_NOOPERHOST = 491; ERR_UMODEUNKNOWNFLAG = 501;\n\t\tERR_USERSDONTMATCH = 502;\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"3c9edac11c6418a263b83967008344ef7fbfa60b","subject":"Also add comma for uniqueness constraints to builtin syntax; enhance patterns for uniqueness","message":"Also add comma for uniqueness constraints to builtin syntax; enhance patterns for uniqueness\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \".\", \"%:\", \"[*<=*]\", \",\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:... | [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [...<=...]`).\"\n\t\t, \"\\n\\nNote that when using unique types in a function or an ADT the container must also be unique.\"\n\t\t, \"For instance, `T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"\\n\\nFunctions have to be split up into arity 1 and the sub functions need to be annotated as well.\"\n\t\t, \"For instance, `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parenthesis when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \"[\", \"]\", \".\", \":\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:... | [...<=...]\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [...<=...]`).\"\n\t\t, \"\\n\\nNote that when using unique types in a function or an ADT the container must also be unique.\"\n\t\t, \"For instance, `T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"\\n\\nFunctions have to be split up into arity 1 and the sub functions need to be annotated as well.\"\n\t\t, \"For instance, `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parenthesis when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"b2eaf2be4b81829671bfe54c1e9ab4f9384031ed","subject":"Don't index the compiler patch","message":"Don't index the compiler patch\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle","old_file":"backend\/builddb.icl","new_file":"backend\/builddb.icl","new_contents":"module builddb\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import const, o\nimport StdList\nimport StdMisc\nimport StdString\nimport StdTuple\n\nimport Data.Either\nfrom Data.Func import $, mapSt\nimport Data.Functor\nimport Data.Maybe\nimport System.CommandLine\nfrom Text import class Text(concat,startsWith), instance Text String\n\nimport TypeDB\nimport Type\nfrom TypeDBFactory import :: DclCache, findModules, getModuleTypes,\n\tconstructor_functions, record_functions\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const False)\n\t , (\"CleanInotify\", const False)\n\t , (\"CleanPrettyPrint\", const False)\n\t , (\"CleanSerial\", const False)\n\t , (\"CleanTypeUnifier\", const False)\n\t , (\"Cloogle\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"GraphCopy\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"Platform\", const False)\n\t , (\"Sapl\", const False)\n\t , (\"SoccerFun\", const False)\n\t , (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"iTasks\", const False)\n\t , (\"libcloogle\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"Platform\/Deprecated\"\n\t , \"Platform\/Data\/Graph\/Inductive\/Query\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t , \"Cloogle\/compiler-patch\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (db, w) = loop cli.root mods newDb w\n\t# db = putFunctions predefFunctions db\n\t# db = putClasses predefClasses db\n\t# db = putTypes predefTypes db\n\t# db = putFunctions (flatten $ map constructor_functions predefTypes) db\n\t# db = putFunctions (flatten $ map record_functions predefTypes) db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] TypeDB *World -> *(TypeDB, *World)\n\tloop _ [] db w = (db,w)\n\tloop root [(lib,mod,iscore):list] db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t# (db, w) = getModuleTypes root mod lib iscore db w\n\t= loop root list db w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ moduleCount db\n\t\t\t\t, functionCount db\n\t\t\t\t, macroCount db\n\t\t\t\t, typeCount db\n\t\t\t\t, classCount db\n\t\t\t\t, instanceCount db\n\t\t\t\t, deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [(Location, ExtendedType)]\npredefFunctions\n\t= [ ( Builtin \"if\"\n\t , ET (Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []) zero\n\t )\n\t , ( Builtin \"dynamic\"\n\t , ET (Func [Var \"a\"] (Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [(Location, Class)]\npredefClasses\n\t= [ ( Builtin \"TC\"\n\t , { class_vars=[\"v\"]\n\t , class_context=[]\n\t , class_documentation=Nothing\n\t , class_members=[]\n\t }\n\t )\n\t ]\n\npredefTypes :: [(Location, ExtendedTypeDef)]\npredefTypes\n\t= [ ( Builtin \"Bool\"\n\t , { deft\n\t & etd_typedef.td_name = \"Bool\"\n\t , etd_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\", { deft & etd_typedef.td_name = \"Int\" } )\n\t , ( Builtin \"Real\", { deft & etd_typedef.td_name = \"Real\" } )\n\t , ( Builtin \"Char\", { deft & etd_typedef.td_name = \"Char\" } )\n\t , ( Builtin \"String\", { deft & etd_typedef.td_name = \"String\",\n\t etd_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\", { deft & etd_typedef.td_name = \"Dynamic\" } )\n\t , ( Builtin \"File\", { deft & etd_typedef.td_name = \"File\" } )\n\t , ( Builtin \"World\", { deft & etd_typedef.td_name = \"World\",\n\t etd_typedef.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {etd_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract}, etd_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n","old_contents":"module builddb\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import const, o\nimport StdList\nimport StdMisc\nimport StdString\nimport StdTuple\n\nimport Data.Either\nfrom Data.Func import $, mapSt\nimport Data.Functor\nimport Data.Maybe\nimport System.CommandLine\nfrom Text import class Text(concat,startsWith), instance Text String\n\nimport TypeDB\nimport Type\nfrom TypeDBFactory import :: DclCache, findModules, getModuleTypes,\n\tconstructor_functions, record_functions\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String -> Bool)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const False)\n\t , (\"CleanInotify\", const False)\n\t , (\"CleanPrettyPrint\", const False)\n\t , (\"CleanSerial\", const False)\n\t , (\"CleanTypeUnifier\", const False)\n\t , (\"Cloogle\", const False)\n\t , (\"Directory\", const False)\n\t , (\"Dynamics\", const False)\n\t , (\"Gast\", const False)\n\t , (\"Generics\", const False)\n\t , (\"GraphCopy\", const False)\n\t , (\"MersenneTwister\", const False)\n\t , (\"ObjectIO\", not o startsWith \"Std\")\n\t , (\"Platform\", const False)\n\t , (\"Sapl\", const False)\n\t , (\"SoccerFun\", const False)\n\t , (\"StdEnv\", const False)\n\t , (\"StdLib\", const False)\n\t , (\"TCPIP\", const False)\n\t , (\"iTasks\", const False)\n\t , (\"libcloogle\", const False)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"Platform\/Deprecated\"\n\t , \"Platform\/Data\/Graph\/Inductive\/Query\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t# (db, w) = loop cli.root mods newDb w\n\t# db = putFunctions predefFunctions db\n\t# db = putClasses predefClasses db\n\t# db = putTypes predefTypes db\n\t# db = putFunctions (flatten $ map constructor_functions predefTypes) db\n\t# db = putFunctions (flatten $ map record_functions predefTypes) db\n\t# io = stderr\n\t# io = printStats db io\n\t# (ok1,w) = fclose io w\n\t# f = saveDb db f\n\t# (ok2,w) = fclose f w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,Bool)] TypeDB *World -> *(TypeDB, *World)\n\tloop _ [] db w = (db,w)\n\tloop root [(lib,mod,iscore):list] db w\n\t# w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t# (db, w) = getModuleTypes root mod lib iscore db w\n\t= loop root list db w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const False):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !TypeDB !*File -> *File\n\tprintStats db f = f\n\t\t<<< \"+-------------+------+\\n\"\n\t\t<<< \"| Modules | \" <<< modules <<< \" |\\n\"\n\t\t<<< \"| Functions | \" <<< funs <<< \" |\\n\"\n\t\t<<< \"| Types | \" <<< types <<< \" |\\n\"\n\t\t<<< \"| Macros | \" <<< macros <<< \" |\\n\"\n\t\t<<< \"| Classes | \" <<< classes <<< \" |\\n\"\n\t\t<<< \"| Instances | \" <<< insts <<< \" |\\n\"\n\t\t<<< \"| Derivations | \" <<< derives <<< \" |\\n\"\n\t\t<<< \"+-------------+------+\\n\"\n\twhere\n\t\t[modules,funs,macros,types,classes,insts,derives:_]\n\t\t\t= map (pad 4)\n\t\t\t\t[ moduleCount db\n\t\t\t\t, functionCount db\n\t\t\t\t, macroCount db\n\t\t\t\t, typeCount db\n\t\t\t\t, classCount db\n\t\t\t\t, instanceCount db\n\t\t\t\t, deriveCount db\n\t\t\t\t]\n\t\tpad n i = {' ' \\\\ _ <- [0..n-size (toString i)-1]} +++ toString i\n\npredefFunctions :: [(Location, ExtendedType)]\npredefFunctions\n\t= [ ( Builtin \"if\"\n\t , ET (Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []) zero\n\t )\n\t , ( Builtin \"dynamic\"\n\t , ET (Func [Var \"a\"] (Type \"Dynamic\" []) []) zero\n\t )\n\t ]\n\npredefClasses :: [(Location, Class)]\npredefClasses\n\t= [ ( Builtin \"TC\"\n\t , { class_vars=[\"v\"]\n\t , class_context=[]\n\t , class_documentation=Nothing\n\t , class_members=[]\n\t }\n\t )\n\t ]\n\npredefTypes :: [(Location, ExtendedTypeDef)]\npredefTypes\n\t= [ ( Builtin \"Bool\"\n\t , { deft\n\t & etd_typedef.td_name = \"Bool\"\n\t , etd_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\", { deft & etd_typedef.td_name = \"Int\" } )\n\t , ( Builtin \"Real\", { deft & etd_typedef.td_name = \"Real\" } )\n\t , ( Builtin \"Char\", { deft & etd_typedef.td_name = \"Char\" } )\n\t , ( Builtin \"String\", { deft & etd_typedef.td_name = \"String\",\n\t etd_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\", { deft & etd_typedef.td_name = \"Dynamic\" } )\n\t , ( Builtin \"File\", { deft & etd_typedef.td_name = \"File\" } )\n\t , ( Builtin \"World\", { deft & etd_typedef.td_name = \"World\",\n\t etd_typedef.td_uniq = True } )\n\t ]\nwhere\n\tdeft = {etd_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract}, etd_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"c5bebd0a75317ccf3d5f722e58fba34839e1f35b","subject":"Match types case insensitively","message":"Match types case insensitively\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"CloogleServer.icl","new_file":"CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , modules :: Maybe [String]\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(String, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , distance :: Int\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ClassResult\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras\nderive JSONDecode Request, Response, Result, ClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , modules = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) +++ \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_NAMETOOLONG :== 129\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,modules,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_NAMETOOLONG \"function name too long\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= filter ((<)(length results) o snd) <$> (mbType >>= flip suggs db)\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !Type !TypeDB -> Maybe [(String, Int)]\n\tsuggs (Func is r cc) db\n\t\t| length is < 3 = Just [let t` = concat $ print False $ Func is` r cc in\n\t\t (t`, length $ search {zero & unify=Just t`} db)\n\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,modules,page} db\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes $ [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t , isModMatchF <$> modules\n\t\t ]\n\t\t# funs = map (makeFunctionResult name mbType Nothing) $ findFunction`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes $ [ (\\t _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (CL lib mod _) _ f _ -> isNameMatch\n\t\t (size n-2) n (FL lib mod f)) <$> name\n\t\t , isModMatchC <$> modules\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,et)) members\n\t\t\/\/ Search types\n\t\t# lcTypeName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case lcTypeName of\n\t\t\t(Just n) = findType` (\\(TL _ _ t) _ -> toLowerCase t == n) db\n\t\t\tNothing = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td) types\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types\n\n\tmakeTypeResult :: (Maybe String) TypeLocation TypeDef -> Result\n\tmakeTypeResult mbName (TL lib mod t) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance\n\t\t\t\t= if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ClassResult)\n\t (FunctionLocation, ExtendedType) -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (FL lib mod fname, ET type tes)\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t }\n\t\t , { func = fname +++ toStrPriority tes.te_priority +++\n\t\t \" :: \" +++ concat (print False type)\n\t\t , unifier = toStrUnifier <$> finish_unification\n\t\t\t\t<$> (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t }\n\t\t )\n\twhere\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification\n\t\t\t\t\t<$> unify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)]\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= levenshtein` orgsearch fname\n\t\twhere\n\t\t\ttypeComplexity :: Type -> Int\n\t\t\ttypeComplexity (Type _ ts) = foldr ((+) o typeComplexity) 1 ts\n\t\t\ttypeComplexity (Func is _ _) = foldr ((+) o typeComplexity) 5 is\n\t\t\ttypeComplexity (Var _) = 1\n\t\t\ttypeComplexity (Cons _ ts) = foldr ((+) o typeComplexity) 1 ts\n\t\t\ttypeComplexity (Uniq t) = 3 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein a b\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) +++ \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatchF :: ![String] FunctionLocation ExtendedType -> Bool\n\tisModMatchF mods (FL _ mod _) _ = isMember mod mods\n\n\tisModMatchC :: ![String] ClassLocation [TypeVar] FunctionName ExtendedType -> Bool\n\tisModMatchC mods (CL _ mod _) _ _ _ = isMember mod mods\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip +++ \" --> \" +++ toString (length data)\n\t\t\t+++ \" results (\" +++ toString return +++ \"; \" +++ msg +++\n\t\t\tif (isJust more_available) (\"; \" +++ toString (fromJust more_available) +++ \" more\") \"\" +++ \")\\n\"\n\tmsgToString _ _ = \"\"\n","old_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf), instance Text String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , modules :: Maybe [String]\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(String, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , distance :: Int\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ClassResult\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras\nderive JSONDecode Request, Response, Result, ClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , modules = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) +++ \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_NAMETOOLONG :== 129\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,modules,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_NAMETOOLONG \"function name too long\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= filter ((<)(length results) o snd) <$> (mbType >>= flip suggs db)\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !Type !TypeDB -> Maybe [(String, Int)]\n\tsuggs (Func is r cc) db\n\t\t| length is < 3 = Just [let t` = concat $ print False $ Func is` r cc in\n\t\t (t`, length $ search {zero & unify=Just t`} db)\n\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,modules,page} db\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes $ [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t , isModMatchF <$> modules\n\t\t ]\n\t\t# funs = map (makeFunctionResult name mbType Nothing) $ findFunction`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes $ [ (\\t _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (CL lib mod _) _ f _ -> isNameMatch\n\t\t (size n-2) n (FL lib mod f)) <$> name\n\t\t , isModMatchC <$> modules\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,et)) members\n\t\t\/\/ Search types\n\t\t# types = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in findType name db)\n\t\t\t[]\n\t\t# types = if (isNothing mbType && isJust name) (findType (fromJust name) db) types\n\t\t# types = map (\\(tl,td) -> makeTypeResult tl td) types\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types\n\n\tmakeTypeResult :: TypeLocation TypeDef -> Result\n\tmakeTypeResult (TL lib mod _) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ClassResult)\n\t (FunctionLocation, ExtendedType) -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (FL lib mod fname, ET type tes)\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t }\n\t\t , { func = fname +++ toStrPriority tes.te_priority +++\n\t\t \" :: \" +++ concat (print False type)\n\t\t , unifier = toStrUnifier <$> finish_unification\n\t\t\t\t<$> (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t }\n\t\t )\n\twhere\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification\n\t\t\t\t\t<$> unify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)]\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t# levdist = levenshtein fname orgsearch\n\t\t\t= if (indexOf orgsearch fname == -1) 0 -100 + levdist\n\t\twhere\n\t\t\ttypeComplexity :: Type -> Int\n\t\t\ttypeComplexity (Type _ ts) = foldr ((+) o typeComplexity) 1 ts\n\t\t\ttypeComplexity (Func is _ _) = foldr ((+) o typeComplexity) 5 is\n\t\t\ttypeComplexity (Var _) = 1\n\t\t\ttypeComplexity (Cons _ ts) = foldr ((+) o typeComplexity) 1 ts\n\t\t\ttypeComplexity (Uniq t) = 3 + typeComplexity t\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) +++ \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatchF :: ![String] FunctionLocation ExtendedType -> Bool\n\tisModMatchF mods (FL _ mod _) _ = isMember mod mods\n\n\tisModMatchC :: ![String] ClassLocation [TypeVar] FunctionName ExtendedType -> Bool\n\tisModMatchC mods (CL _ mod _) _ _ _ = isMember mod mods\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip +++ \" --> \" +++ toString (length data)\n\t\t\t+++ \" results (\" +++ toString return +++ \"; \" +++ msg +++\n\t\t\tif (isJust more_available) (\"; \" +++ toString (fromJust more_available) +++ \" more\") \"\" +++ \")\\n\"\n\tmsgToString _ _ = \"\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"a5d6131905cd21b8cf87f2157fc7c5d440845eb7","subject":"Fix notices (only for private messages; channels get privmsg)","message":"Fix notices (only for private messages; channels get privmsg)\n","repos":"clean-cloogle\/clean-irc","old_file":"cloogleirc.icl","new_file":"cloogleirc.icl","new_contents":"module cloogleirc\n\nimport Cloogle\nimport GenPrint\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nimport Data.Either\nfrom Data.Func import $, mapSt\nfrom Text import class Text(..), instance Text String, instance + String\n\nimport Internet.HTTP\n\nimport Text.JSON\n\nimport Text.URI\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad, instance Monad Maybe, >>=\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport System.CommandLine\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\nimport IRC\nimport IRCBot\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# s = if (startsWith \"http:\/\/\" s) s (if (startsWith \"https:\/\/\" s) s (\"http:\/\/\" + s))\n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doHTTPRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} 10000 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\ncloogle :: String *World -> (String, *World)\ncloogle data w\n# (mer, w) = doHTTPRequestL\n\t\t{ newHTTPRequest\n\t\t& req_path = \"\/api.php\"\n\t\t, req_query = \"?str=\" + urlEncode data\n\t\t, req_headers = 'DM'.fromList [(\"User-Agent\", \"cloogle-irc\")]\n\t\t, server_name = \"cloogle.org\"\n\t\t, server_port = 80} 10000 10 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= case fromJSON $ fromString resp.HTTPResponse.rsp_data of\n\tNothing = (\"couldn't parse json\", w)\n\tJust clr = (\"Results for \" + data + \" -- https:\/\/cloogle.org\/#\" +\n\t\treplaceSubString \"+\" \"%20\" (urlEncode data) + \"\\n\" +\n\t\tprocessResults clr, w)\n\twhere\n\t\tprocessResults :: Response -> String\n\t\tprocessResults resp\n\t\t| resp.return > 127 = \"Failed: return code: \" + toString resp.return + \", \" + resp.msg\n\t\t= join \"\\n\" $ map processResult $ take 3 resp.data\n\t\t\n\t\tprocessResult :: Result -> String\n\t\tprocessResult (FunctionResult (br, {func}))\n\t\t\t= \"Function in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ func\n\t\tprocessResult (TypeResult (br, {type}))\n\t\t\t= \"Type in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ limitResults type\n\t\tprocessResult (ClassResult (br, {class_name,class_funs}))\n\t\t\t= \"Class in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ class_name +++ \" with \"\n\t\t\t\t+++ toString (length class_funs) +++ \" class functions\"\n\t\tprocessResult (ModuleResult (br, _))\n\t\t\t= \"Module in \" +++ br.library +++ \": \" +++ br.modul\n\n\t\tlimitResults :: String -> String\n\t\tlimitResults s\n\t\t# lines = split \"\\n\" s\n\t\t| length lines > 4 = limitResults (join \"\\n\" (take 3 lines) + \"\\n...\")\n\t\t= join \"\\n\" (map maxWidth lines)\n\t\t\n\t\tmaxWidth :: String -> String\n\t\tmaxWidth s\n\t\t| size s > 80 = subString 0 77 s + \"...\"\n\t\t= s\n\n:: BotSettings =\n\t\t{ bs_nick :: String\n\t\t, bs_nickserv :: Maybe String\n\t\t, bs_autojoin :: [String]\n\t\t, bs_port :: Int\n\t\t, bs_server :: String\n\t\t}\n\nStart :: *World -> (MaybeErrorString (), *World)\nStart w\n# ([arg0:args], w) = getCommandLine w\n# bs = parseCLI args \n| isError bs = (Error $ \"\\n\" +++ fromError bs +++ \"\\n\", w)\n# (Ok bs) = bs\n= bot (bs.bs_server, bs.bs_port) (startup bs) shutdown () process w\n\twhere\n\t\tparseCLI :: [String] -> MaybeErrorString BotSettings\n\t\tparseCLI [] = Ok\n\t\t\t{ bs_nick = \"clooglebot\"\n\t\t\t, bs_nickserv = Nothing\n\t\t\t, bs_autojoin = []\n\t\t\t, bs_port = 6667\n\t\t\t, bs_server = \"irc.freenode.net\"\n\t\t\t}\n\t\tparseCLI [a:as]\n\t\t| a == \"-n\" || a == \"--nick\"\n\t\t\t= arg1 \"--nick\" as \\a c->{c & bs_nick=a}\n\t\t| a == \"-ns\" || a == \"--nickserv\"\n\t\t\t= arg1 \"--nickserv\" as \\a c->{c & bs_nickserv=Just a}\n\t\t| a == \"-a\" || a == \"--autojoin\"\n\t\t\t= arg1 \"--autojoin\" as \\a c->{c & bs_autojoin=c.bs_autojoin ++ [a]}\n\t\t| a == \"-p\" || a == \"--port\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_port=toInt a}\n\t\t| a == \"-s\" || a == \"--server\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_server=a}\n\t\t| a == \"-h\" || a == \"--help\" = Error $ join \"\\n\" $\n\t\t\t[ \"Usage: cloogle [OPTS]\"\n\t\t\t, \"Options:\"\n\t\t\t, \"\\t--nick\/-n NICKNAME Use the given nickname instead of clooglebot\"\n\t\t\t, \"\\t--nickserv\/-ns PW Identify via the given password with NickServ\"\n\t\t\t, \"\\t--port\/-p PORT Use the given port instead of port 6667\"\n\t\t\t, \"\\t--server\/-s SERVER Use the given server instead of irc.freenode.net\"\n\t\t\t, \"\\t--autojoin\/-a CHANNEL Add CHANNEL to the autojoin list. This command \"\n\t\t\t, \"\\t can be called multiple times. Beware that #\"\n\t\t\t, \"\\t has to be escaped in most shells\"\n\t\t\t]\n\t\t= Error $ \"Unknown option: \" +++ a\n\n\t\targ1 name [] _ = Error $ name +++ \" requires an argument\"\n\t\targ1 name [a:as] f = parseCLI as >>= Ok o f a\n\n\t\tnickserv pw = PRIVMSG (CSepList [\"NickServ\"]) $ \"IDENTIFY \" +++ pw\n\n\t\ttoPrefix c = {irc_prefix=Nothing,irc_command=Right c}\n\n\t\tstartup bs = map toPrefix $\n\t\t\t[ NICK bs.bs_nick Nothing\n\t\t\t, USER \"cloogle\" \"cloogle\" \"cloogle\" \"Cloogle bot\"\n\t\t\t]++ maybe [] (pure o nickserv) bs.bs_nickserv\n\t\t\t ++ if (isEmpty bs.bs_autojoin) []\n\t\t\t\t[JOIN (CSepList bs.bs_autojoin) Nothing]\n\t\tshutdown = map toPrefix [QUIT $ Just \"Bye\"]\n\n\t\tprocess :: IRCMessage () *World -> (Maybe [IRCMessage], (), *World)\n\t\tprocess im s w = case im.irc_command of\n\t\t\tLeft numr = (Just [], (), w)\n\t\t\tRight cmd = case process` im.irc_prefix cmd w of\n\t\t\t\t(Nothing, w) = (Nothing, (), w)\n\t\t\t\t(Just cs, w) = (Just $ map toPrefix cs, (), w)\n\n\t\tprocess` :: (Maybe (Either IRCUser String)) IRCCommand *World -> (Maybe [IRCCommand], *World)\n\t\tprocess` (Just (Left user)) (PRIVMSG t m) w\n\t\t\t| m == \"!restart\" = (Nothing, w)\n\t\t\t| m.[0] == '!'\n\t\t\t\t# (msgs, w) = realProcess (split \" \" $ m % (1, size m)) w\n\t\t\t\t= (Just $ map reply msgs, w)\n\t\t\t= (Just [], w)\n\t\twhere\n\t\t\treply = case (\\(CSepList [t:_]) -> t.[0]) t of\n\t\t\t\t'#' -> PRIVMSG t\n\t\t\t\t_ -> NOTICE user.irc_nick\n\t\tprocess` _ (PING t mt) w = (Just [PONG t mt], w)\n\t\tprocess` _ _ w = (Just [], w)\n\n\t\trealProcess :: [String] *World -> ([String], *World)\n\t\trealProcess [\"help\",x:xs] w = ((case x of\n\t\t\t\"help\" =\n\t\t\t\t[ \"Usage: !help [ARG]\"\n\t\t\t\t, \"Show this help, or the specific help of the argument\"]\n\t\t\t\"ping\" =\n\t\t\t\t[ \"Usage: !ping [ARG [ARG ...]]\"\n\t\t\t\t, \"Ping the bot, it will pong the arguments back\"]\n\t\t\t\"shorten\" =\n\t\t\t\t[ \"Usage: !shorten URL [URL [URL ...]]\"\n\t\t\t\t, \"Shorten the given urls with the cloo.gl url shortener\"]\n\t\t\t\"query\" =\n\t\t\t\t[ \"Usage: !query QUERY\"\n\t\t\t\t, \"Query QUERY in cloogle and return the results\"]\n\t\t\t\"restart\" =\n\t\t\t\t[ \"Usage: !restart\"\n\t\t\t\t, \"Restart the bot\"]\n\t\t\tx = [\"Unknown command: \" +++ x]\n\t\t\t), w)\n\t\trealProcess [\"help\"] w = (\n\t\t\t[\"Type !help cmd for command specific help\"\n\t\t\t,\"available commands: help, ping, shorten, query, restart\"], w)\n\t\trealProcess [\"ping\":xs] w = ([\"pong \" +++ join \" \" xs], w)\n\t\trealProcess [\"shorten\":xs] w = case xs of\n\t\t\t[] = ([\"shorten requires at least one argument\"], w)\n\t\t\txs = mapSt shorten xs w\n\t\trealProcess [\"query\":xs] w = case xs of\n\t\t\t[] = ([\"query requires one or more arguments\"], w)\n\t\t\txs = appFst (split \"\\n\") $ cloogle (join \" \" xs) w\n\t\trealProcess [\"restart\":_] w = ([\"restart takes no arguments\"], w)\n\t\trealProcess [c:_] w = ([join \" \" [\n\t\t\t\"Unknown cmd: \", c, \", type !help to get help\"]], w)\n","old_contents":"module cloogleirc\n\nimport Cloogle\nimport GenPrint\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nimport Data.Either\nfrom Data.Func import $, mapSt\nfrom Text import class Text(..), instance Text String, instance + String\n\nimport Internet.HTTP\n\nimport Text.JSON\n\nimport Text.URI\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad, instance Monad Maybe, >>=\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport System.CommandLine\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\nimport IRC\nimport IRCBot\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# s = if (startsWith \"http:\/\/\" s) s (if (startsWith \"https:\/\/\" s) s (\"http:\/\/\" + s))\n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doHTTPRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} 10000 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\ncloogle :: String *World -> (String, *World)\ncloogle data w\n# (mer, w) = doHTTPRequestL\n\t\t{ newHTTPRequest\n\t\t& req_path = \"\/api.php\"\n\t\t, req_query = \"?str=\" + urlEncode data\n\t\t, req_headers = 'DM'.fromList [(\"User-Agent\", \"cloogle-irc\")]\n\t\t, server_name = \"cloogle.org\"\n\t\t, server_port = 80} 10000 10 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= case fromJSON $ fromString resp.HTTPResponse.rsp_data of\n\tNothing = (\"couldn't parse json\", w)\n\tJust clr = (\"Results for \" + data + \" -- https:\/\/cloogle.org\/#\" +\n\t\treplaceSubString \"+\" \"%20\" (urlEncode data) + \"\\n\" +\n\t\tprocessResults clr, w)\n\twhere\n\t\tprocessResults :: Response -> String\n\t\tprocessResults resp\n\t\t| resp.return > 127 = \"Failed: return code: \" + toString resp.return + \", \" + resp.msg\n\t\t= join \"\\n\" $ map processResult $ take 3 resp.data\n\t\t\n\t\tprocessResult :: Result -> String\n\t\tprocessResult (FunctionResult (br, {func}))\n\t\t\t= \"Function in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ func\n\t\tprocessResult (TypeResult (br, {type}))\n\t\t\t= \"Type in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ limitResults type\n\t\tprocessResult (ClassResult (br, {class_name,class_funs}))\n\t\t\t= \"Class in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ class_name +++ \" with \"\n\t\t\t\t+++ toString (length class_funs) +++ \" class functions\"\n\t\tprocessResult (ModuleResult (br, _))\n\t\t\t= \"Module in \" +++ br.library +++ \": \" +++ br.modul\n\n\t\tlimitResults :: String -> String\n\t\tlimitResults s\n\t\t# lines = split \"\\n\" s\n\t\t| length lines > 4 = limitResults (join \"\\n\" (take 3 lines) + \"\\n...\")\n\t\t= join \"\\n\" (map maxWidth lines)\n\t\t\n\t\tmaxWidth :: String -> String\n\t\tmaxWidth s\n\t\t| size s > 80 = subString 0 77 s + \"...\"\n\t\t= s\n\n:: BotSettings =\n\t\t{ bs_nick :: String\n\t\t, bs_nickserv :: Maybe String\n\t\t, bs_autojoin :: [String]\n\t\t, bs_port :: Int\n\t\t, bs_server :: String\n\t\t}\n\nStart :: *World -> (MaybeErrorString (), *World)\nStart w\n# ([arg0:args], w) = getCommandLine w\n# bs = parseCLI args \n| isError bs = (Error $ \"\\n\" +++ fromError bs +++ \"\\n\", w)\n# (Ok bs) = bs\n= bot (bs.bs_server, bs.bs_port) (startup bs) shutdown () process w\n\twhere\n\t\tparseCLI :: [String] -> MaybeErrorString BotSettings\n\t\tparseCLI [] = Ok\n\t\t\t{ bs_nick = \"clooglebot\"\n\t\t\t, bs_nickserv = Nothing\n\t\t\t, bs_autojoin = []\n\t\t\t, bs_port = 6667\n\t\t\t, bs_server = \"irc.freenode.net\"\n\t\t\t}\n\t\tparseCLI [a:as]\n\t\t| a == \"-n\" || a == \"--nick\"\n\t\t\t= arg1 \"--nick\" as \\a c->{c & bs_nick=a}\n\t\t| a == \"-ns\" || a == \"--nickserv\"\n\t\t\t= arg1 \"--nickserv\" as \\a c->{c & bs_nickserv=Just a}\n\t\t| a == \"-a\" || a == \"--autojoin\"\n\t\t\t= arg1 \"--autojoin\" as \\a c->{c & bs_autojoin=c.bs_autojoin ++ [a]}\n\t\t| a == \"-p\" || a == \"--port\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_port=toInt a}\n\t\t| a == \"-s\" || a == \"--server\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_server=a}\n\t\t| a == \"-h\" || a == \"--help\" = Error $ join \"\\n\" $\n\t\t\t[ \"Usage: cloogle [OPTS]\"\n\t\t\t, \"Options:\"\n\t\t\t, \"\\t--nick\/-n NICKNAME Use the given nickname instead of clooglebot\"\n\t\t\t, \"\\t--nickserv\/-ns PW Identify via the given password with NickServ\"\n\t\t\t, \"\\t--port\/-p PORT Use the given port instead of port 6667\"\n\t\t\t, \"\\t--server\/-s SERVER Use the given server instead of irc.freenode.net\"\n\t\t\t, \"\\t--autojoin\/-a CHANNEL Add CHANNEL to the autojoin list. This command \"\n\t\t\t, \"\\t can be called multiple times. Beware that #\"\n\t\t\t, \"\\t has to be escaped in most shells\"\n\t\t\t]\n\t\t= Error $ \"Unknown option: \" +++ a\n\n\t\targ1 name [] _ = Error $ name +++ \" requires an argument\"\n\t\targ1 name [a:as] f = parseCLI as >>= Ok o f a\n\n\t\tnickserv pw = PRIVMSG (CSepList [\"NickServ\"]) $ \"IDENTIFY \" +++ pw\n\n\t\ttoPrefix c = {irc_prefix=Nothing,irc_command=Right c}\n\n\t\tstartup bs = map toPrefix $\n\t\t\t[ NICK bs.bs_nick Nothing\n\t\t\t, USER \"cloogle\" \"cloogle\" \"cloogle\" \"Cloogle bot\"\n\t\t\t]++ maybe [] (pure o nickserv) bs.bs_nickserv\n\t\t\t ++ if (isEmpty bs.bs_autojoin) []\n\t\t\t\t[JOIN (CSepList bs.bs_autojoin) Nothing]\n\t\tshutdown = map toPrefix [QUIT $ Just \"Bye\"]\n\n\t\tprocess :: IRCMessage () *World -> (Maybe [IRCMessage], (), *World)\n\t\tprocess im s w = case im.irc_command of\n\t\t\tLeft numr = (Just [], (), w)\n\t\t\tRight cmd = case process` im.irc_prefix cmd w of\n\t\t\t\t(Nothing, w) = (Nothing, (), w)\n\t\t\t\t(Just cs, w) = (Just $ map toPrefix cs, (), w)\n\n\t\tprocess` :: (Maybe (Either IRCUser String)) IRCCommand *World -> (Maybe [IRCCommand], *World)\n\t\tprocess` (Just (Left user)) (PRIVMSG t m) w\n\t\t\t| m == \"!restart\" = (Nothing, w)\n\t\t\t| m.[0] == '!'\n\t\t\t\t# (msgs, w) = realProcess (split \" \" $ m % (1, size m)) w\n\t\t\t\t= (Just $ map (NOTICE recipient) msgs, w)\n\t\t\t= (Just [], w)\n\t\twhere\n\t\t\trecipient = case (\\(CSepList [t:_]) -> t.[0]) t of\n\t\t\t\t'#' -> t\n\t\t\t\t_ -> CSepList [user.irc_nick]\n\t\tprocess` _ (PING t mt) w = (Just [PONG t mt], w)\n\t\tprocess` _ _ w = (Just [], w)\n\n\t\trealProcess :: [String] *World -> ([String], *World)\n\t\trealProcess [\"help\",x:xs] w = ((case x of\n\t\t\t\"help\" =\n\t\t\t\t[ \"Usage: !help [ARG]\"\n\t\t\t\t, \"Show this help, or the specific help of the argument\"]\n\t\t\t\"ping\" =\n\t\t\t\t[ \"Usage: !ping [ARG [ARG ...]]\"\n\t\t\t\t, \"Ping the bot, it will pong the arguments back\"]\n\t\t\t\"shorten\" =\n\t\t\t\t[ \"Usage: !shorten URL [URL [URL ...]]\"\n\t\t\t\t, \"Shorten the given urls with the cloo.gl url shortener\"]\n\t\t\t\"query\" =\n\t\t\t\t[ \"Usage: !query QUERY\"\n\t\t\t\t, \"Query QUERY in cloogle and return the results\"]\n\t\t\t\"restart\" =\n\t\t\t\t[ \"Usage: !restart\"\n\t\t\t\t, \"Restart the bot\"]\n\t\t\tx = [\"Unknown command: \" +++ x]\n\t\t\t), w)\n\t\trealProcess [\"help\"] w = (\n\t\t\t[\"Type !help cmd for command specific help\"\n\t\t\t,\"available commands: help, ping, shorten, query, restart\"], w)\n\t\trealProcess [\"ping\":xs] w = ([\"pong \" +++ join \" \" xs], w)\n\t\trealProcess [\"shorten\":xs] w = case xs of\n\t\t\t[] = ([\"shorten requires at least one argument\"], w)\n\t\t\txs = mapSt shorten xs w\n\t\trealProcess [\"query\":xs] w = case xs of\n\t\t\t[] = ([\"query requires one or more arguments\"], w)\n\t\t\txs = appFst (split \"\\n\") $ cloogle (join \" \" xs) w\n\t\trealProcess [\"restart\":_] w = ([\"restart takes no arguments\"], w)\n\t\trealProcess [c:_] w = ([join \" \" [\n\t\t\t\"Unknown cmd: \", c, \", type !help to get help\"]], w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"fa1c9f24c3a14e3ee9420cebc2d96e13df2b0890","subject":"Fix syntax error","message":"Fix syntax error\n","repos":"dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \"[\", \"]\", \".\", \":\"]\n\t, syntax_code =\n\t\t[\"*...\"\n\t\t,\". ...\" \n\t\t,\"v:.. | [v ..]\" \n\t\t]\n\t, syntax_description = \"Annotates a type with its uniqueness. A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [..]`). Note that when using unique types in a function or an ADT the container must also be unique. e.g. `T = T (Int, *File)` has to be `T = T *(Int, *File)`. Functions have to be split up into arity 1 and the sub functions need to be annotated as well. e.g. `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/World is unique\"\n\t\t, \"f :: .a -> .a \/\/f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \"[\", \"]\", \".\", \":\"]\n\t, syntax_code =\n\t\t[\"*...\"\n\t\t,\". ...\" \n\t\t,\"v:.. | [v ..]\" \n\t, syntax_description = \"Annotates a type with its uniqueness. A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [..]`). Note that when using unique types in a function or an ADT the container must also be unique. e.g. `T = T (Int, *File)` has to be `T = T *(Int, *File)`. Functions have to be split up into arity 1 and the sub functions need to be annotated as well. e.g. `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/World is unique\"\n\t\t, \"f :: .a -> .a \/\/f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"f31780da2c92882e9c92cefcfad9ba73b0d5313f","subject":"Oops - DCL files have to be EOL=LF otherwise unzipping does not work well","message":"Oops - DCL files have to be EOL=LF otherwise unzipping does not work well\n\ngit-svn-id: 152f48a1866dc7886cc2b83d2001e6645df26423@1004095 13f79535-47bb-0310-9956-ffa450edef68\n","repos":"apache\/commons-exec,sgoeschl\/commons-exec,sgoeschl\/commons-exec,apache\/commons-exec,mohanaraosv\/commons-exec,mohanaraosv\/commons-exec","old_file":"src\/test\/scripts\/forever.dcl","new_file":"src\/test\/scripts\/forever.dcl","new_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Licensed to the Apache Software Foundation (ASF) under one or more\n$! contributor license agreements. See the NOTICE file distributed with\n$! this work for additional information regarding copyright ownership.\n$! The ASF licenses this file to You under the Apache License, Version 2.0\n$! (the \"License\"); you may not use this file except in compliance with\n$! the License. You may obtain a copy of the License at\n$!\n$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n$!\n$! Unless required by applicable law or agreed to in writing, software\n$! distributed under the License is distributed on an \"AS IS\" BASIS,\n$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n$! See the License for the specific language governing permissions and\n$! limitations under the License.\n$! \n$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! run an infinite loop so the script will never ever terminate\n$!\n$! Suppress timeout warning\n$ l_msg=f$environment(\"MESSAGE\")\n$ SET MESSAGE \/NOFACILITY \/NOIDENTIFICATION \/NOSEVERITY \/NOTEXT\n$!\n$ SET NOON\n$ ON CONTROL_Y THEN GOTO DONE\n$ close\/nolog OUT\n$ open\/write OUT [.target]forever.txt ! create the output file\n$LOOP:\n$ write OUT \".\"\n$ read \/prompt=\".\"\/time_out=1 sys$command dummy\n$ GOTO LOOP\n$!\n$DONE:\n$ close\/nolog OUT\n$! Restore message settings\n$ SET MESSAGE 'l_msg'","old_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Licensed to the Apache Software Foundation (ASF) under one or more\n$! contributor license agreements. See the NOTICE file distributed with\n$! this work for additional information regarding copyright ownership.\n$! The ASF licenses this file to You under the Apache License, Version 2.0\n$! (the \"License\"); you may not use this file except in compliance with\n$! the License. You may obtain a copy of the License at\n$!\n$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n$!\n$! Unless required by applicable law or agreed to in writing, software\n$! distributed under the License is distributed on an \"AS IS\" BASIS,\n$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n$! See the License for the specific language governing permissions and\n$! limitations under the License.\n$! \n$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! run an infinite loop so the script will never ever terminate\n$!\n$! Suppress timeout warning\n$ l_msg=f$environment(\"MESSAGE\")\n$ SET MESSAGE \/NOFACILITY \/NOIDENTIFICATION \/NOSEVERITY \/NOTEXT\n$!\n$ SET NOON\n$ ON CONTROL_Y THEN GOTO DONE\n$ close\/nolog OUT\n$ open\/write OUT [.target]forever.txt ! create the output file\n$LOOP:\n$ write OUT \".\"\n$ read \/prompt=\".\"\/time_out=1 sys$command dummy\n$ GOTO LOOP\n$!\n$DONE:\n$ close\/nolog OUT\n$! Restore message settings\n$ SET MESSAGE 'l_msg'","returncode":0,"stderr":"","license":"apache-2.0","lang":"Clean"} {"commit":"992a0d9c4827f8e56c47cddf737477da921e53ad","subject":"Fix incorrect cache prefetching when page is not given","message":"Fix incorrect cache prefetching when page is not given\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Tuple\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , libraries :: Maybe ([String], Bool)\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , dcl_line :: Maybe Int\n , icl_line :: Maybe Int\n , distance :: Int\n , builtin :: Maybe Bool\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , recordfield_of :: Maybe String\n , generic_derivations :: Maybe [(String, [LocationResult])]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n , type_instances :: [(String, [String], [LocationResult])]\n , type_derivations :: [(String, [LocationResult])]\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [([String], [LocationResult])]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: LocationResult :== (String, String, Maybe Int)\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = MaybeError Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , libraries = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache request w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey request, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err E_NORESULTS \"No results\")\n\t\t\t{ return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\trespond :: Response *World -> *(Response, CacheKey, *World)\n\t\trespond r w = (r, cacheKey request, writeCache LongTerm request r w)\n\n\t\tcachePages :: Int Int Response [Result] *World -> *World\n\t\tcachePages _ _ _ [] w = w\n\t\tcachePages 0 _ _ _ w = w\n\t\tcachePages npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { request & page = ((+) i) <$> (request.page <|> pure 0) }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n (Location lib mod Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\loc _ _ _ -> toLowerCase (getName loc) == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = Nothing\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" | \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [([concat (print False t) \\\\ t <- ts], map loc ls)\n\t\t \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = Nothing\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = tes.te_iclline\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,builtin) = case fl of\n\t\t\t(Location l m ln f) = (l, m, f, ln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln _) = (lib, mod, ln)\n\n\tlog :: (LogMessage (Maybe Request) Response CacheKey) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _ _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available} ck) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg\n\t\t\t+ if (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\"\n\t\t\t+ \"; cache: \" + ck + \")\\n\"\n\tmsgToString _ _ = \"\"\n","old_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Tuple\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Cache\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , libraries :: Maybe ([String], Bool)\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , dcl_line :: Maybe Int\n , icl_line :: Maybe Int\n , distance :: Int\n , builtin :: Maybe Bool\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , recordfield_of :: Maybe String\n , generic_derivations :: Maybe [(String, [LocationResult])]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n , type_instances :: [(String, [String], [LocationResult])]\n , type_derivations :: [(String, [LocationResult])]\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [([String], [LocationResult])]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: LocationResult :== (String, String, Maybe Int)\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = MaybeError Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , libraries = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\nCACHE_PREFETCH :== 5\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) (Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, CacheKey, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", \"\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t\/\/Check cache\n\t\t# (mbResponse, w) = readCache request w\n\t\t| isJust mbResponse\n\t\t\t# r = fromJust mbResponse\n\t\t\t= ({r & return = if (r.return == 0) 1 r.return}, cacheKey request, w)\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= respond (err E_INVALIDNAME \"Function name too long\") w\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= respond (err E_INVALIDNAME \"Name cannot contain spaces\") w\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= respond (err E_INVALIDTYPE \"Couldn't parse type\") w\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# (results,nextpages) = splitAt MAX_RESULTS results\n\t\t\/\/ Response\n\t\t# response = if (isEmpty results)\n\t\t\t(err E_NORESULTS \"No results\")\n\t\t\t{ return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t\/\/ Save page prefetches\n\t\t# w = cachePages CACHE_PREFETCH 1 response nextpages w\n\t\t\/\/ Save cache file\n\t\t= respond response w\n\twhere\n\t\trespond :: Response *World -> *(Response, CacheKey, *World)\n\t\trespond r w = (r, cacheKey request, writeCache LongTerm request r w)\n\n\t\tcachePages :: Int Int Response [Result] *World -> *World\n\t\tcachePages _ _ _ [] w = w\n\t\tcachePages 0 _ _ _ w = w\n\t\tcachePages npages i response results w\n\t\t# w = writeCache Brief req` resp` w\n\t\t= cachePages (npages - 1) (i + 1) response keep w\n\t\twhere\n\t\t\treq` = { request & page = ((+) i) <$> request.page <|> pure 0 }\n\t\t\tresp` =\n\t\t\t\t{ response\n\t\t\t\t& more_available = Just $ max 0 (length results - MAX_RESULTS)\n\t\t\t\t, data = give\n\t\t\t\t}\n\t\t\t(give,keep) = splitAt MAX_RESULTS results\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= [makeTypeResult (Just typeName) l td db \\\\ (l,td) <- types]\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n*2\/3) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n*2\/3) n loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _) _ _ f _ -> isNameMatch\n\t\t (size n*2\/3) n (Location lib mod Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td db) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\loc _ _ _ -> toLowerCase (getName loc) == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult rec=:(Builtin _, _, _, _) db\n\t\t= ClassResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance = -100\n\t\t , builtin = Just True\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResult rec=:(Location lib mod line cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = Nothing\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , makeClassResultExtras rec db\n\t\t )\n\tmakeClassResultExtras :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> ClassResultExtras\n\tmakeClassResultExtras (l, vars, cc, funs) db\n\t\t= { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" | \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [([concat (print False t) \\\\ t <- ts], map loc ls)\n\t\t \\\\ (ts,ls) <- getInstances cls db]\n\t\t }\n\twhere\n\t\tcls = case l of\n\t\t\tBuiltin c = c\n\t\t\tLocation _ _ _ c = c\n\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef TypeDB -> Result\n\tmakeTypeResult mbName (Location lib mod line t) td db\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td db\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , icl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td\n\t\t , type_instances = map (appSnd3 (map (concat o (print False)))) $\n\t\t map (appThd3 (map loc)) $ getTypeInstances t db\n\t\t , type_derivations = map (appSnd (map loc)) $ getTypeDerivations t db\n\t\t }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = Nothing\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , icl_line = tes.te_iclline\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,builtin) = case fl of\n\t\t\t(Location l m ln f) = (l, m, f, ln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein [c \\\\ c <-: a] [c \\\\ c <-: b]\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein [c \\\\ c <-: n1] [c \\\\ c <-: n2] <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> LocationResult\n\tloc (Location lib mod ln _) = (lib, mod, ln)\n\n\tlog :: (LogMessage (Maybe Request) Response CacheKey) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _ _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response CacheKey) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available} ck) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg\n\t\t\t+ if (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\"\n\t\t\t+ \"; cache: \" + ck + \")\\n\"\n\tmsgToString _ _ = \"\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"505d611cc739c97f5cdb1888cba420d7df7c95f7","subject":"Fix unifier","message":"Fix unifier\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"CloogleServer.icl","new_file":"CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf), instance Text String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , modules :: Maybe [String]\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(String, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , distance :: Int\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ClassResult\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras\nderive JSONDecode Request, Response, Result, ClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , modules = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) +++ \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_NAMETOOLONG :== 129\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,modules,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_NAMETOOLONG \"function name too long\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= filter ((<)(length results) o snd) <$> (mbType >>= flip suggs db)\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !Type !TypeDB -> Maybe [(String, Int)]\n\tsuggs (Func is r cc) db\n\t\t| length is < 3 = Just [let t` = concat $ print False $ Func is` r cc in\n\t\t (t`, length $ search {zero & unify=Just t`} db)\n\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,modules,page} db\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes $ [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t , isModMatchF <$> modules\n\t\t ]\n\t\t# funs = map (makeFunctionResult name mbType Nothing) $ findFunction`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes $ [ (\\t _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (CL lib mod _) _ f _ -> isNameMatch\n\t\t (size n-2) n (FL lib mod f)) <$> name\n\t\t , isModMatchC <$> modules\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,et)) members\n\t\t\/\/ Search types\n\t\t# types = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in findType name db)\n\t\t\t[]\n\t\t# types = if (isNothing mbType && isJust name) (findType (fromJust name) db) types\n\t\t# types = map (\\(tl,td) -> makeTypeResult tl td) types\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types\n\n\tmakeTypeResult :: TypeLocation TypeDef -> Result\n\tmakeTypeResult (TL lib mod _) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ClassResult)\n\t (FunctionLocation, ExtendedType) -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (FL lib mod fname, ET type tes)\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t }\n\t\t , { func = fname +++ toStrPriority tes.te_priority +++\n\t\t \" :: \" +++ concat (print False type)\n\t\t , unifier = toStrUnifier <$> finish_unification\n\t\t\t\t<$> (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t }\n\t\t )\n\twhere\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification\n\t\t\t\t\t<$> unify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)]\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t# levdist = levenshtein fname orgsearch\n\t\t\t= if (indexOf orgsearch fname == -1) 0 -100 + levdist\n\t\twhere\n\t\t\ttypeComplexity :: Type -> Int\n\t\t\ttypeComplexity (Type _ ts) = foldr ((+) o typeComplexity) 1 ts\n\t\t\ttypeComplexity (Func is _ _) = foldr ((+) o typeComplexity) 5 is\n\t\t\ttypeComplexity (Var _) = 1\n\t\t\ttypeComplexity (Cons _ ts) = foldr ((+) o typeComplexity) 1 ts\n\t\t\ttypeComplexity (Uniq t) = 3 + typeComplexity t\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) +++ \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatchF :: ![String] FunctionLocation ExtendedType -> Bool\n\tisModMatchF mods (FL _ mod _) _ = isMember mod mods\n\n\tisModMatchC :: ![String] ClassLocation [TypeVar] FunctionName ExtendedType -> Bool\n\tisModMatchC mods (CL _ mod _) _ _ _ = isMember mod mods\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip +++ \" --> \" +++ toString (length data)\n\t\t\t+++ \" results (\" +++ toString return +++ \"; \" +++ msg +++\n\t\t\tif (isJust more_available) (\"; \" +++ toString (fromJust more_available) +++ \" more\") \"\" +++ \")\\n\"\n\tmsgToString _ _ = \"\"\n","old_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf), instance Text String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , modules :: Maybe [String]\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(String, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , distance :: Int\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ClassResult\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras\nderive JSONDecode Request, Response, Result, ClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , modules = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) +++ \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_NAMETOOLONG :== 129\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,modules,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_NAMETOOLONG \"function name too long\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= filter ((<)(length results) o snd) <$> (mbType >>= flip suggs db)\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !Type !TypeDB -> Maybe [(String, Int)]\n\tsuggs (Func is r cc) db\n\t\t| length is < 3 = Just [let t` = concat $ print False $ Func is` r cc in\n\t\t (t`, length $ search {zero & unify=Just t`} db)\n\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,modules,page} db\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes $ [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t , isModMatchF <$> modules\n\t\t ]\n\t\t# funs = map (makeFunctionResult name mbType Nothing) $ findFunction`` filts db\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes $ [ (\\t _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (CL lib mod _) _ f _ -> isNameMatch\n\t\t (size n-2) n (FL lib mod f)) <$> name\n\t\t , isModMatchC <$> modules\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(CL lib mod cls,vs,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (FL lib mod f,et)) members\n\t\t\/\/ Search types\n\t\t# types = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in findType name db)\n\t\t\t[]\n\t\t# types = if (isNothing mbType && isJust name) (findType (fromJust name) db) types\n\t\t# types = map (\\(tl,td) -> makeTypeResult tl td) types\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types\n\n\tmakeTypeResult :: TypeLocation TypeDef -> Result\n\tmakeTypeResult (TL lib mod _) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ClassResult)\n\t (FunctionLocation, ExtendedType) -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (FL lib mod fname, ET type tes)\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t }\n\t\t , { func = fname +++ toStrPriority tes.te_priority +++\n\t\t \" :: \" +++ concat (print False type)\n\t\t , unifier = toStrUnifier <$> finish_unification\n\t\t\t\t<$> (orgsearchtype >>= unify [] type)\n\t\t , cls = mbCls\n\t\t }\n\t\t )\n\twhere\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification\n\t\t\t\t\t<$> unify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)]\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t# levdist = levenshtein fname orgsearch\n\t\t\t= if (indexOf orgsearch fname == -1) 0 -100 + levdist\n\t\twhere\n\t\t\ttypeComplexity :: Type -> Int\n\t\t\ttypeComplexity (Type _ ts) = foldr ((+) o typeComplexity) 1 ts\n\t\t\ttypeComplexity (Func is _ _) = foldr ((+) o typeComplexity) 5 is\n\t\t\ttypeComplexity (Var _) = 1\n\t\t\ttypeComplexity (Cons _ ts) = foldr ((+) o typeComplexity) 1 ts\n\t\t\ttypeComplexity (Uniq t) = 3 + typeComplexity t\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) +++ \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String FunctionLocation -> Bool\n\tisNameMatch maxdist n1 (FL _ _ n2)\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: n2})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatchF :: ![String] FunctionLocation ExtendedType -> Bool\n\tisModMatchF mods (FL _ mod _) _ = isMember mod mods\n\n\tisModMatchC :: ![String] ClassLocation [TypeVar] FunctionName ExtendedType -> Bool\n\tisModMatchC mods (CL _ mod _) _ _ _ = isMember mod mods\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t -> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip +++ \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip +++ \" <-- \" +++ toString a +++ \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip +++ \" --> \" +++ toString (length data)\n\t\t\t+++ \" results (\" +++ toString return +++ \"; \" +++ msg +++\n\t\t\tif (isJust more_available) (\"; \" +++ toString (fromJust more_available) +++ \" more\") \"\" +++ \")\\n\"\n\tmsgToString _ _ = \"\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"4972384debd644c8a9ee43ed84fe32abdad234f7","subject":"Expand documentation of EADTs","message":"Expand documentation of EADTs\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = map exact [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = map exact [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"8055c769a3606dbf4bea0c63a26951a6b89baf36","subject":"Rename typemap to functionmap","message":"Rename typemap to functionmap\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"TypeDB.icl","new_file":"TypeDB.icl","new_contents":"implementation module TypeDB\n\n\/\/ Standard libraries\nimport StdEnv\nfrom Data.Func import $\nimport Data.Map\nimport Data.Maybe\nimport Text.JSON\n\n\/\/ CleanTypeUnifier\nimport Type\n\n:: TypeDB = { functionmap :: Map FunctionLocation ExtendedType\n , classmap :: Map ClassLocation ([TypeVar],[(FunctionName, ExtendedType)])\n , instancemap :: Map Class [Type]\n }\n\n(<+) infixr 5 :: a b -> [String] | print a & print b\n(<+) a b = print a ++ print b\n\nderive gEq ClassOrGeneric, FunctionLocation, ClassLocation, Type, TypeDB,\n\tTypeExtras, TE_Priority, ExtendedType\nderive JSONEncode ClassOrGeneric, FunctionLocation, ClassLocation, Type,\n\tTypeDB, TypeExtras, TE_Priority, ExtendedType\nderive JSONDecode ClassOrGeneric, FunctionLocation, ClassLocation, Type,\n\tTypeDB, TypeExtras, TE_Priority, ExtendedType\n\ninstance zero TypeDB where zero = { functionmap = newMap\n , classmap = newMap\n , instancemap = newMap\n }\n\ninstance < FunctionLocation where (<) (FL a b c) (FL d e f) = (a,b,c) < (d,e,f)\ninstance print FunctionLocation\nwhere print (FL lib mod fn) = fn <+ \" in \" <+ mod <+ \" in \" <+ lib\n\ninstance < ClassLocation where (<) (CL a b c) (CL d e f) = (a,b,c) < (d,e,f)\n\ninstance print TE_Priority\nwhere\n\tprint (LeftAssoc i) = \"infixl \" <+ i\n\tprint (RightAssoc i) = \"infixr \" <+ i\n\tprint (NoAssoc i) = \"infix \" <+ i\n\ngetType :: FunctionLocation TypeDB -> Maybe ExtendedType\ngetType loc {functionmap} = get loc functionmap\n\nputType :: FunctionLocation ExtendedType TypeDB -> TypeDB\nputType fl t tdb=:{functionmap} = { tdb & functionmap = put fl t functionmap }\n\nputTypes :: [(FunctionLocation, ExtendedType)] TypeDB -> TypeDB\nputTypes ts tdb = foldr (\\(loc,t) db -> putType loc t db) tdb ts\n\nfindType :: FunctionName TypeDB -> [(FunctionLocation, ExtendedType)]\nfindType f db=:{functionmap} = toList $ filterWithKey (\\(FL _ _ f`) _->f==f`) functionmap\n\nfindType` :: (FunctionLocation ExtendedType -> Bool) TypeDB\n\t\t-> [(FunctionLocation, ExtendedType)]\nfindType` f {functionmap} = toList $ filterWithKey f functionmap\n\nfindType`` :: [(FunctionLocation ExtendedType -> Bool)] TypeDB\n\t\t-> [(FunctionLocation, ExtendedType)]\nfindType`` fs {functionmap} = toList $ foldr filterWithKey functionmap fs\n\ngetInstances :: Class TypeDB -> [Type]\ngetInstances c {instancemap} = if (isNothing ts) [] (fromJust ts)\nwhere ts = get c instancemap\n\nputInstance :: Class Type TypeDB -> TypeDB\nputInstance c t db=:{instancemap} = {db & instancemap=put c ts instancemap}\nwhere\n ts = removeDup [t : getInstances c db]\n\nputInstances :: Class [Type] TypeDB -> TypeDB\nputInstances c ts db = foldr (\\t db -> putInstance c t db) db ts\n\nputInstancess :: [(Class, [Type])] TypeDB -> TypeDB\nputInstancess is db = foldr (\\(c,ts) db -> putInstances c ts db) db is\n\ngetClass :: ClassLocation TypeDB -> Maybe ([TypeVar],[(FunctionName,ExtendedType)])\ngetClass loc {classmap} = get loc classmap\n\nputClass :: ClassLocation [TypeVar] [(FunctionName, ExtendedType)] TypeDB -> TypeDB\nputClass cl tvs fs db=:{classmap} = {db & classmap = put cl (tvs,fs) classmap}\n\nputClasses :: [(ClassLocation, [TypeVar], [(FunctionName, ExtendedType)])] TypeDB -> TypeDB\nputClasses cs db = foldr (\\(cl,tvs,fs) db -> putClass cl tvs fs db) db cs\n\nfindClass :: Class TypeDB -> [(ClassLocation, [TypeVar], [(FunctionName, ExtendedType)])]\nfindClass c {classmap} = map (\\(k,(x,y))->(k,x,y)) results\nwhere results = toList $ filterWithKey (\\(CL _ _ c`) _->c==c`) classmap\n\nfindClass` :: (ClassLocation [TypeVar] [(FunctionName,ExtendedType)] -> Bool) TypeDB\n\t\t-> [(ClassLocation, [TypeVar], [(FunctionName,ExtendedType)])]\nfindClass` f {classmap} = map (\\(k,(x,y))->(k,x,y)) results\nwhere results = toList $ filterWithKey (\\cl (vs,fs)->f cl vs fs) classmap\n\nfindClassMembers` :: (ClassLocation [TypeVar] FunctionName ExtendedType -> Bool) TypeDB\n\t\t-> [(ClassLocation, [TypeVar], FunctionName, ExtendedType)]\nfindClassMembers` f {classmap} = filter (app4 f) $ flatten members\nwhere\n\tmembers = map (\\(cl,(vs,fs))->[(cl,vs,f,t) \\\\ (f,t)<-fs]) $ toList classmap\n\nfindClassMembers`` :: [(ClassLocation [TypeVar] FunctionName ExtendedType -> Bool)]\n\t\tTypeDB -> [(ClassLocation, [TypeVar], FunctionName, ExtendedType)]\nfindClassMembers`` fs {classmap} = foldr (filter o app4) all_members fs\nwhere\n\tall_members = [(cl,vs,f,t) \\\\ (cl,(vs,fs)) <- toList classmap, (f,t) <- fs]\n\nsearchExact :: Type TypeDB -> [(FunctionLocation, ExtendedType)]\nsearchExact t db = filter ((\\(ET t` _)->t==t`) o snd) $ toList db.functionmap\n\nsearchUnifiable :: Type TypeDB\n -> [(FunctionLocation, ExtendedType, [TVAssignment], [TVAssignment])]\nsearchUnifiable t db = search` $ toList db.functionmap\nwhere\n search` :: [(FunctionLocation,ExtendedType)] \n -> [(FunctionLocation,ExtendedType,[TVAssignment],[TVAssignment])]\n search` [] = []\n search` [(l,ET t` tes):list]\n # tvas = unify [] t t`\n | isNothing tvas = search` list\n # (tvas1,tvas2) = fromJust tvas\n = [(l,ET t` tes,tvas1,tvas2):search` list]\n\nnewDb :: TypeDB\nnewDb = zero\n\nopenDb :: *File -> *(Maybe TypeDB, *File)\nopenDb f\n# (data, f) = freadline f\n= (fromJSON $ fromString data, f)\n\nsaveDb :: TypeDB *File -> *File\nsaveDb db f = fwrites (toString $ toJSON db) f\n\napp4 f (a,b,c,d) :== f a b c d\n\n","old_contents":"implementation module TypeDB\n\n\/\/ Standard libraries\nimport StdEnv\nfrom Data.Func import $\nimport Data.Map\nimport Data.Maybe\nimport Text.JSON\n\n\/\/ CleanTypeUnifier\nimport Type\n\n:: TypeDB = { typemap :: Map FunctionLocation ExtendedType\n , classmap :: Map ClassLocation ([TypeVar],[(FunctionName, ExtendedType)])\n , instancemap :: Map Class [Type]\n }\n\n(<+) infixr 5 :: a b -> [String] | print a & print b\n(<+) a b = print a ++ print b\n\nderive gEq ClassOrGeneric, FunctionLocation, ClassLocation, Type, TypeDB,\n\tTypeExtras, TE_Priority, ExtendedType\nderive JSONEncode ClassOrGeneric, FunctionLocation, ClassLocation, Type,\n\tTypeDB, TypeExtras, TE_Priority, ExtendedType\nderive JSONDecode ClassOrGeneric, FunctionLocation, ClassLocation, Type,\n\tTypeDB, TypeExtras, TE_Priority, ExtendedType\n\ninstance zero TypeDB where zero = { typemap = newMap\n , classmap = newMap\n , instancemap = newMap\n }\n\ninstance < FunctionLocation where (<) (FL a b c) (FL d e f) = (a,b,c) < (d,e,f)\ninstance print FunctionLocation\nwhere print (FL lib mod fn) = fn <+ \" in \" <+ mod <+ \" in \" <+ lib\n\ninstance < ClassLocation where (<) (CL a b c) (CL d e f) = (a,b,c) < (d,e,f)\n\ninstance print TE_Priority\nwhere\n\tprint (LeftAssoc i) = \"infixl \" <+ i\n\tprint (RightAssoc i) = \"infixr \" <+ i\n\tprint (NoAssoc i) = \"infix \" <+ i\n\ngetType :: FunctionLocation TypeDB -> Maybe ExtendedType\ngetType loc {typemap} = get loc typemap\n\nputType :: FunctionLocation ExtendedType TypeDB -> TypeDB\nputType fl t tdb=:{typemap} = { tdb & typemap = put fl t typemap }\n\nputTypes :: [(FunctionLocation, ExtendedType)] TypeDB -> TypeDB\nputTypes ts tdb = foldr (\\(loc,t) db -> putType loc t db) tdb ts\n\nfindType :: FunctionName TypeDB -> [(FunctionLocation, ExtendedType)]\nfindType f db=:{typemap} = toList $ filterWithKey (\\(FL _ _ f`) _->f==f`) typemap\n\nfindType` :: (FunctionLocation ExtendedType -> Bool) TypeDB\n\t\t-> [(FunctionLocation, ExtendedType)]\nfindType` f {typemap} = toList $ filterWithKey f typemap\n\nfindType`` :: [(FunctionLocation ExtendedType -> Bool)] TypeDB\n\t\t-> [(FunctionLocation, ExtendedType)]\nfindType`` fs {typemap} = toList $ foldr filterWithKey typemap fs\n\ngetInstances :: Class TypeDB -> [Type]\ngetInstances c {instancemap} = if (isNothing ts) [] (fromJust ts)\nwhere ts = get c instancemap\n\nputInstance :: Class Type TypeDB -> TypeDB\nputInstance c t db=:{instancemap} = {db & instancemap=put c ts instancemap}\nwhere\n ts = removeDup [t : getInstances c db]\n\nputInstances :: Class [Type] TypeDB -> TypeDB\nputInstances c ts db = foldr (\\t db -> putInstance c t db) db ts\n\nputInstancess :: [(Class, [Type])] TypeDB -> TypeDB\nputInstancess is db = foldr (\\(c,ts) db -> putInstances c ts db) db is\n\ngetClass :: ClassLocation TypeDB -> Maybe ([TypeVar],[(FunctionName,ExtendedType)])\ngetClass loc {classmap} = get loc classmap\n\nputClass :: ClassLocation [TypeVar] [(FunctionName, ExtendedType)] TypeDB -> TypeDB\nputClass cl tvs fs db=:{classmap} = {db & classmap = put cl (tvs,fs) classmap}\n\nputClasses :: [(ClassLocation, [TypeVar], [(FunctionName, ExtendedType)])] TypeDB -> TypeDB\nputClasses cs db = foldr (\\(cl,tvs,fs) db -> putClass cl tvs fs db) db cs\n\nfindClass :: Class TypeDB -> [(ClassLocation, [TypeVar], [(FunctionName, ExtendedType)])]\nfindClass c {classmap} = map (\\(k,(x,y))->(k,x,y)) results\nwhere results = toList $ filterWithKey (\\(CL _ _ c`) _->c==c`) classmap\n\nfindClass` :: (ClassLocation [TypeVar] [(FunctionName,ExtendedType)] -> Bool) TypeDB\n\t\t-> [(ClassLocation, [TypeVar], [(FunctionName,ExtendedType)])]\nfindClass` f {classmap} = map (\\(k,(x,y))->(k,x,y)) results\nwhere results = toList $ filterWithKey (\\cl (vs,fs)->f cl vs fs) classmap\n\nfindClassMembers` :: (ClassLocation [TypeVar] FunctionName ExtendedType -> Bool) TypeDB\n\t\t-> [(ClassLocation, [TypeVar], FunctionName, ExtendedType)]\nfindClassMembers` f {classmap} = filter (app4 f) $ flatten members\nwhere\n\tmembers = map (\\(cl,(vs,fs))->[(cl,vs,f,t) \\\\ (f,t)<-fs]) $ toList classmap\n\nfindClassMembers`` :: [(ClassLocation [TypeVar] FunctionName ExtendedType -> Bool)]\n\t\tTypeDB -> [(ClassLocation, [TypeVar], FunctionName, ExtendedType)]\nfindClassMembers`` fs {classmap} = foldr (filter o app4) all_members fs\nwhere\n\tall_members = [(cl,vs,f,t) \\\\ (cl,(vs,fs)) <- toList classmap, (f,t) <- fs]\n\nsearchExact :: Type TypeDB -> [(FunctionLocation, ExtendedType)]\nsearchExact t db = filter ((\\(ET t` _)->t==t`) o snd) $ toList db.typemap\n\nsearchUnifiable :: Type TypeDB\n -> [(FunctionLocation, ExtendedType, [TVAssignment], [TVAssignment])]\nsearchUnifiable t db = search` $ toList db.typemap\nwhere\n search` :: [(FunctionLocation,ExtendedType)] \n -> [(FunctionLocation,ExtendedType,[TVAssignment],[TVAssignment])]\n search` [] = []\n search` [(l,ET t` tes):list]\n # tvas = unify [] t t`\n | isNothing tvas = search` list\n # (tvas1,tvas2) = fromJust tvas\n = [(l,ET t` tes,tvas1,tvas2):search` list]\n\nnewDb :: TypeDB\nnewDb = zero\n\nopenDb :: *File -> *(Maybe TypeDB, *File)\nopenDb f\n# (data, f) = freadline f\n= (fromJSON $ fromString data, f)\n\nsaveDb :: TypeDB *File -> *File\nsaveDb db f = fwrites (toString $ toJSON db) f\n\napp4 f (a,b,c,d) :== f a b c d\n\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"2d52ed5527db84fbf9e5b20be494f323c782bc03","subject":"Add syntax documentation (#180)","message":"Add syntax documentation (#180)\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = \"Specifies the implementation of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = map exact [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_context =\n\t{ syntax_title = \"Type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = map exact [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"1bd3179ea9aeb802fda02f03b60338841458873f","subject":"Add = and -> documentation for case expressions (#180)","message":"Add = and -> documentation for case expressions (#180)\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\"]\n\t, syntax_code = [\"*...\"]\n\t, syntax_description = \"Annotates a type to be unique.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\"]\n\t, syntax_code = [\"*...\"]\n\t, syntax_description = \"Annotates a type to be unique.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"bd5cec4495792198cb3270f5baeac3a362af606c","subject":"add requestL","message":"add requestL\n","repos":"clean-cloogle\/clean-irc","old_file":"cloogle.icl","new_file":"cloogle.icl","new_contents":"module cloogle\n\nimport GenPrint\nimport IRC\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nfrom Data.Func import $\nfrom Text import class Text(..), instance Text String, instance + String\n\nimport Text.URI\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad, instance Monad Maybe\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\n\ncommands :: [String]\ncommands = map toString\n\t[NICK \"clooglebot\"\n\t,USER \"cloogle\" 0 \"Cloogle bot\"\n\t,JOIN [(\"#cloogle\", Nothing)]\n\t]\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nKEY :== \"PRIVMSG #cloogle :!\"\n\ndoRequest :: HTTPRequest *World -> *(MaybeErrorString HTTPResponse, *World)\ndoRequest req w\n# (ip,w) = lookupIPAddress server_name w\n| isNothing ip\n\t= (Error $ \"DNS lookup for \" + server_name + \" failed.\", w)\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, req.server_port) w\n| rpt == TR_Expired\n\t= (Error $ \"Connection to \" + toString ip + \" timed out.\", w)\n| rpt == TR_NoSuccess\n\t= (Error $ \"Could not connect to \" + server_name + \".\", w)\n# (Just {sChannel,rChannel}) = chan\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq req) sChannel w\n| rpt <> TR_Success\n\t= (Error $ \"Could not send request to \" + server_name + \".\", w)\n# (rpt,resp,rChannel,w) = receive_MT TIMEOUT rChannel w\n| rpt <> TR_Success\n\t= (Error $ \"Did not receive a reply from \" + server_name + \".\", w)\n# resp = 'CM'.join $ parseResponse <$> toString <$> resp\n| isNothing resp\n\t# w = closeChannel sChannel (closeRChannel rChannel w)\n\t= (Error $ \"Server did not respond with HTTP.\", w)\n# (resp,rChannel,w) = receiveRest (fromJust resp) rChannel w\n# w = closeChannel sChannel (closeRChannel rChannel w)\n= (resp,w)\nwhere\n\tserver_name = req.server_name\n\treceiveRest resp chan w\n\t# cl = lookup \"Content-Length\" resp.HTTPResponse.rsp_headers\n\t| isNothing cl\n\t\t= (Ok resp, chan, w)\n\t| size resp.rsp_data >= toInt (fromJust cl)\n\t\t= (Ok resp, chan, w)\n\t# (rpt,newresp,chan,w) = receive_MT TIMEOUT chan w\n\t| rpt <> TR_Success\n\t\t= (Error $ server_name + \" hung up during transmission.\", chan, w)\n\t= receiveRest {resp & rsp_data=resp.rsp_data + toString (fromJust newresp)} chan w\n\nimport StdMisc\nimport StdDebug\n\ndoRequestL :: HTTPRequest Int *World -> *(MaybeErrorString HTTPResponse, *World)\ndoRequestL req 0 w = (Error \"Maximal redirect numbe exceeded\", w)\ndoRequestL req maxRedirects w\n| not (trace_tn $ toString req) = undef\n# (er, w) = doRequest req w\n| isError er = (er, w)\n# resp = fromOk er\n| isMember resp.HTTPResponse.rsp_code [301, 302, 303, 307, 308]\n\t= case lookup \"Location\" resp.HTTPResponse.rsp_headers of\n\t\tNothing = (Error $ \"Redirect given but no Location header\", w)\n\t\tJust loc = case parseURI loc of\n\t\t\tNothing = (Error $ \"Redirect URI couldn't be parsed\", w)\n\t\t\tJust uri = doRequestL {req \n\t\t\t\t& server_name = maybe loc id uri.uriRegName\n\t\t\t\t, server_port = maybe 80 id uri.uriPort\n\t\t\t\t, req_path = uri.uriPath\n\t\t\t\t, req_query = maybe \"\" ((+++) \"?\") uri.uriQuery\n\t\t\t\t} (maxRedirects-1) w\n= (er, w)\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# s = if (startsWith \"http:\/\/\" s) s (if (startsWith \"https:\/\/\" s) s (\"http:\/\/\" + s))\n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\ncloogle :: String *World -> (String, *World)\ncloogle data w\n# (mer, w) = doRequestL\n\t\t{ newHTTPRequest\n\t\t& req_path = \"\/api.php\"\n\t\t, req_query = \"?str=\" + urlEncode data\n\t\t, server_name = \"cloogle.org\"\n\t\t, server_port = 80} 10 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\nsend :: [String] TCP_DuplexChannel *World -> (TCP_DuplexChannel, *World)\nsend [] chan w = (chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = abort \"Could not send request\\n\"\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\nrecv :: TCP_DuplexChannel *World -> (Maybe String, TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = abort \"Halp?\\n\"\n= (toString <$> resp, {sChannel=sChannel,rChannel=rChannel}, w)\n\nmsg :: (String -> IRCCommands)\nmsg = PRIVMSG \"#cloogle\"\n\nprocess :: *File TCP_DuplexChannel *World -> (*File, TCP_DuplexChannel, *World)\nprocess io chan w \n# (mr, chan, w) = recv chan w\n| isNothing mr = process io chan w\n# resp = fromJust mr\n#! io = io <<< (\"Received: \" +++ resp +++ \"\\n\")\n# ind = indexOf KEY resp\n| ind >= 0\n\t# cmd = split \" \" $ rtrim $ subString (ind + size KEY) (size resp) resp\n\t#! io = io <<< (\"Received command: \" +++ printToString cmd +++ \"\\n\")\n\t# (w, toSend) = case cmd of\n\t\t[\"stop\":_] = (w, Nothing)\n\t\t[\"ping\":xs] = (w, Just [msg $ \"pong \" +++ join \" \" xs])\n\t\t[\"query\":xs]\n\t\t\t# (s, w) = cloogle (join \" \" xs) w\n\t\t\t= (w, Just [msg s])\n\t\t[\"short\"] = (w, Just [msg $ \"short requires an url argument\"])\n\t\t[\"short\":xs]\n\t\t\t# (s, w) = shorten (join \" \" xs) w\n\t\t\t= (w, Just [msg s])\n\t\t[\"help\"] = (w, Just \n\t\t\t[msg \"type !help cmd for command specific help\"\n\t\t\t,msg \"available commands: help, ping, query, short\"])\n\t\t[\"help\":c:_] = (w, case c of\n\t\t\t\"help\" = Just [msg \"help [CMD] - I will print general help or the help of CMD\"] \n\t\t\t\"ping\" = Just [msg \"ping [TXT] - I will reply with pong and the optionar TXT\"] \n\t\t\t\"query\" = Just [msg \"query QUERY - I will send QUERY to cloogle and post the results\"]\n\t\t\t\"short\" = Just [msg \"short URL - I will give the url to https:\/\/cloo.gl shortening service and post back the result\"]\n\t\t\t_ = Just [msg \"Unknown command\"])\n\t\t[c:_] = (w, Just [msg $ join \" \" [\"unknown command: \" , c, \", type !help to get help\"]])\n\t| isNothing toSend = (io, chan, w)\n\t# (chan, w) = send (map toString $ fromJust toSend) chan w\n\t= process io chan w\n| indexOf \"PING :\" resp >= 0\n\t# cmd = rtrim $ subString (indexOf \"PING :\" resp + size \"PING :\") (size resp) resp\n\t#! io = io <<< (toString $ PONG cmd Nothing) <<< \"\\n\"\n\t# (chan, w) = send [toString $ PONG cmd Nothing] chan w\n\t= process io chan w\n= process io chan w\n\nStart :: *World -> (String, *World)\nStart w = cloogle \"Monad\" w\n\/\/Start :: *World -> *World\n\/\/Start w\n\/\/# (io, w) = stdio w\n\/\/# (ip, w) = lookupIPAddress SERVER w\n\/\/| isNothing ip = abort $ \"DNS lookup for \" +++ SERVER +++ \" failed\\n\"\n\/\/# (Just ip) = ip\n\/\/# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, 6667) w\n\/\/| rpt == TR_Expired = abort $ \"Connection to \" +++ SERVER +++ \" timed out\\n\"\n\/\/| rpt == TR_NoSuccess = abort $ \"Could not connect to \" +++ SERVER +++ \"\\n\"\n\/\/# chan = fromJust chan\n\/\/# (chan, w) = send commands chan w\n\/\/# (io, chan, w) = process io chan w\n\/\/# ({sChannel,rChannel}, w) = send [toString $ QUIT Nothing] chan w\n\/\/# (_, w) = fclose io w\n\/\/= closeChannel sChannel (closeRChannel rChannel w)\n","old_contents":"module cloogle\n\nimport GenPrint\nimport IRC\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nfrom Data.Func import $\nfrom Text import class Text(..), instance Text String, instance + String\n\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad, instance Monad Maybe\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\n\ncommands :: [String]\ncommands = map toString\n\t[NICK \"clooglebot\"\n\t,USER \"cloogle\" 0 \"Cloogle bot\"\n\t,JOIN [(\"#cloogle\", Nothing)]\n\t]\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nKEY :== \"PRIVMSG #cloogle :!\"\n\ndoRequest :: HTTPRequest *World -> *(MaybeErrorString HTTPResponse, *World)\ndoRequest req w\n# (ip,w) = lookupIPAddress server_name w\n| isNothing ip\n\t= (Error $ \"DNS lookup for \" + server_name + \" failed.\", w)\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, req.server_port) w\n| rpt == TR_Expired\n\t= (Error $ \"Connection to \" + toString ip + \" timed out.\", w)\n| rpt == TR_NoSuccess\n\t= (Error $ \"Could not connect to \" + server_name + \".\", w)\n# (Just {sChannel,rChannel}) = chan\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq req) sChannel w\n| rpt <> TR_Success\n\t= (Error $ \"Could not send request to \" + server_name + \".\", w)\n# (rpt,resp,rChannel,w) = receive_MT TIMEOUT rChannel w\n| rpt <> TR_Success\n\t= (Error $ \"Did not receive a reply from \" + server_name + \".\", w)\n# resp = 'CM'.join $ parseResponse <$> toString <$> resp\n| isNothing resp\n\t# w = closeChannel sChannel (closeRChannel rChannel w)\n\t= (Error $ \"Server did not respond with HTTP.\", w)\n# (resp,rChannel,w) = receiveRest (fromJust resp) rChannel w\n# w = closeChannel sChannel (closeRChannel rChannel w)\n= (resp,w)\nwhere\n\tserver_name = req.server_name\n\treceiveRest resp chan w\n\t# cl = lookup \"Content-Length\" resp.HTTPResponse.rsp_headers\n\t| isNothing cl\n\t\t= (Ok resp, chan, w)\n\t| size resp.rsp_data >= toInt (fromJust cl)\n\t\t= (Ok resp, chan, w)\n\t# (rpt,newresp,chan,w) = receive_MT TIMEOUT chan w\n\t| rpt <> TR_Success\n\t\t= (Error $ server_name + \" hung up during transmission.\", chan, w)\n\t= receiveRest {resp & rsp_data=resp.rsp_data + toString (fromJust newresp)} chan w\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\nsend :: [String] TCP_DuplexChannel *World -> (TCP_DuplexChannel, *World)\nsend [] chan w = (chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = abort \"Could not send request\\n\"\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\nrecv :: TCP_DuplexChannel *World -> (Maybe String, TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = abort \"Halp?\\n\"\n= (toString <$> resp, {sChannel=sChannel,rChannel=rChannel}, w)\n\nmsg :: (String -> IRCCommands)\nmsg = PRIVMSG \"#cloogle\"\n\nprocess :: *File TCP_DuplexChannel *World -> (*File, TCP_DuplexChannel, *World)\nprocess io chan w \n# (mr, chan, w) = recv chan w\n| isNothing mr = process io chan w\n# resp = fromJust mr\n#! io = io <<< (\"Received: \" +++ resp +++ \"\\n\")\n# ind = indexOf KEY resp\n| ind >= 0\n\t# cmd = split \" \" $ rtrim $ subString (ind + size KEY) (size resp) resp\n\t#! io = io <<< (\"Received command: \" +++ printToString cmd +++ \"\\n\")\n\t# (w, toSend) = case cmd of\n\t\t[\"stop\":_] = (w, Nothing)\n\t\t[\"ping\":xs] = (w, Just [msg $ \"pong \" +++ join \" \" xs])\n\t\t[\"short\"] = (w, Just [msg $ \"short requires an url argument\"])\n\t\t[\"short\":xs]\n\t\t\t# (s, w) = shorten (join \" \" xs) w\n\t\t\t= (w, Just [msg s])\n\t\t[\"help\"] = (w, Just \n\t\t\t[msg \"type !help cmd for command specific help\"\n\t\t\t,msg \"available commands: help, short, ping\"])\n\t\t[\"help\":c:_] = (w, case c of\n\t\t\t\"help\" = Just [msg \"help [CMD] - I will print general help or the help of CMD\"] \n\t\t\t\"short\" = Just [msg \"short URL - I will give the url to https:\/\/cloo.gl shortening service and post back the result\"]\n\t\t\t\"ping\" = Just [msg \"ping [TXT] - I will reply with pong and the optionar TXT\"] \n\t\t\t_ = Just [msg \"Unknown command\"])\n\t\t[c:_] = (w, Just [msg $ join \" \" [\"unknown command: \" , c, \", type !help to get help\"]])\n\t| isNothing toSend = (io, chan, w)\n\t# (chan, w) = send (map toString $ fromJust toSend) chan w\n\t= process io chan w\n| indexOf \"PING :\" resp >= 0\n\t# cmd = rtrim $ subString (indexOf \"PING :\" resp + size \"PING :\") (size resp) resp\n\t#! io = io <<< (toString $ PONG cmd Nothing) <<< \"\\n\"\n\t# (chan, w) = send [toString $ PONG cmd Nothing] chan w\n\t= process io chan w\n= process io chan w\n\nStart :: *World -> *World\nStart w\n# (io, w) = stdio w\n# (ip, w) = lookupIPAddress SERVER w\n| isNothing ip = abort $ \"DNS lookup for \" +++ SERVER +++ \" failed\\n\"\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, 6667) w\n| rpt == TR_Expired = abort $ \"Connection to \" +++ SERVER +++ \" timed out\\n\"\n| rpt == TR_NoSuccess = abort $ \"Could not connect to \" +++ SERVER +++ \"\\n\"\n# chan = fromJust chan\n# (chan, w) = send commands chan w\n# (io, chan, w) = process io chan w\n# ({sChannel,rChannel}, w) = send [toString $ QUIT Nothing] chan w\n# (_, w) = fclose io w\n= closeChannel sChannel (closeRChannel rChannel w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"c4d3c5e35db5c158047a488330aa56f58a9466bb","subject":"Fix builddb","message":"Fix builddb\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/builddb.icl","new_file":"backend\/builddb.icl","new_contents":"module builddb\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import const, id, o\nimport StdList\nimport StdMisc\nimport StdString\nimport StdTuple\n\nimport Data.Either\nfrom Data.Func import $, mapSt\nimport Data.Functor\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nfrom Text import class Text(concat,startsWith), instance Text String\n\nimport CloogleDB\nimport Type\nfrom CloogleDBFactory import :: TemporaryDB, newTemporaryDb, finaliseDb,\n\tfindModules, indexModule, constructor_functions, record_functions\n\nimport Builtins\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String ModuleEntry -> ModuleEntry)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const id)\n\t , (\"CleanInotify\", const id)\n\t , (\"CleanPrettyPrint\", const id)\n\t , (\"CleanSerial\", const id)\n\t , (\"CleanSnappy\", const id)\n\t , (\"CleanTypeUnifier\", const id)\n\t , (\"Cloogle\", const id)\n\t , (\"Directory\", const id)\n\t , (\"Dynamics\", const id)\n\t , (\"Gast\", const id)\n\t , (\"Generics\", const id)\n\t , (\"GraphCopy\", const id)\n\t , (\"MersenneTwister\", const id)\n\t , (\"ObjectIO\", \\s me -> {me & me_is_core=not (startsWith \"Std\" s)})\n\t , (\"Platform\", const id)\n\t , (\"Sapl\", const id)\n\t , (\"SoccerFun\", const \\me -> {me & me_is_app=True})\n\t , (\"StdEnv\", const id)\n\t , (\"StdLib\", const id)\n\t , (\"TCPIP\", const id)\n\t , (\"iTasks\", const id)\n\t , (\"clean-compiler\", const \\me -> {me & me_is_app=True})\n\t , (\"clean-ide\", const \\me -> {me & me_is_app=True})\n\t , (\"libcloogle\", const id)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"Platform\/Deprecated\"\n\t , \"Platform\/Data\/Graph\/Inductive\/Query\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart :: *World -> *World\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t#! (db, w) = loop cli.root mods newTemporaryDb w\n\t#! db = finaliseDb builtins db\n\t#! (db,err) = printStats db stderr\n\t#! (ok1,w) = fclose err w\n\t#! (db,f) = saveDB db f\n\t#! (ok2,w) = fclose f w\n\t#! (_,dbg,w) = fopen \"typetree.dot\" FWriteText w\n\t#! (db,dbg) = writeTypeTree db dbg\n\t#! (_,w) = fclose dbg w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,String ModuleEntry -> ModuleEntry)] !TemporaryDB !*World -> *(!TemporaryDB, !*World)\n\tloop _ [] db w = (db,w)\n\tloop root [(lib,mod,modf):list] db w\n\t#! w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t#! (db, w) = indexModule False root mod lib modf db w\n\t#! db = eval_all_nodes db\n\t= loop root list db w\n\n\tbuiltins =\n\t\tmap FunctionEntry builtin_functions ++\n\t\tmap ClassEntry builtin_classes ++\n\t\tmap TypeDefEntry builtin_types ++\n\t\tmap FunctionEntry (concatMap constructor_functions builtin_types) ++\n\t\tmap FunctionEntry (concatMap record_functions builtin_types) ++\n\t\tmap SyntaxEntry builtin_syntax\n\n\teval_all_nodes :: !.a -> .a \/\/ From GraphCopy\n\teval_all_nodes g = code {\n\t\tpush_a 0\n\t\t.d 1 0\n\t\tjsr\t_eval_to_nf\n\t\t.o 0 0\n\t}\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const id):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !*CloogleDB !*File -> *(*CloogleDB, *File)\n\tprintStats db f\n\t# (s,db) = dbStats db\n\t= (db, f\n\t\t<<< \"+-------------------+-------+\\n\"\n\t\t<< \"Modules\" <-- s.n_modules\n\t\t<< \"Functions\" <-- s.n_functions\n\t\t<< \"With types\" <-- s.n_functions_with_type\n\t\t<< \"Unique types\" <-- s.n_unique_types\n\t\t<< \"Type tree depth\" <-- s.type_tree_depth\n\t\t<< \"Type definitions\" <-- s.n_type_definitions\n\t\t<< \"Classes\" <-- s.n_classes\n\t\t<< \"Instances\" <-- s.n_instances\n\t\t<< \"Derivations\" <-- s.n_derivations\n\t\t<< \"Syntax constructs\" <-- s.n_syntax_constructs\n\t\t<<< \"+-------------------+-------+\\n\")\n\twhere\n\t\t(<<) infixl :: *File String -> *File\n\t\t(<<) f s = f <<< \"| \" <<< rpad 17 s <<< \" | \"\n\n\t\t(<--) infixl :: *File Int -> *File\n\t\t(<--) f i = f <<< lpad 5 i <<< \" |\\n\"\n\n\t\tlpad n s = {' ' \\\\ _ <- [0..n-size (toString s)-1]} +++ toString s\n\t\trpad n s = toString s +++ {' ' \\\\ _ <- [0..n-size (toString s)-1]}\n","old_contents":"module builddb\n\nimport StdArray\nimport StdBool\nimport StdFile\nfrom StdFunc import const, id, o\nimport StdList\nimport StdMisc\nimport StdString\nimport StdTuple\n\nimport Data.Either\nfrom Data.Func import $, mapSt\nimport Data.Functor\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nfrom Text import class Text(concat,startsWith), instance Text String\n\nimport CloogleDB\nimport Type\nfrom CloogleDBFactory import :: TemporaryDB, newTemporaryDb, finaliseDb,\n\tfindModules, indexModule, constructor_functions, record_functions\n\nimport Builtins\n\n:: CLI = { help :: Bool\n , version :: Bool\n , root :: String\n , libs :: [(String, String ModuleEntry -> ModuleEntry)]\n , exclude :: [String]\n }\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ (\"ArgEnv\", const id)\n\t , (\"CleanInotify\", const id)\n\t , (\"CleanPrettyPrint\", const id)\n\t , (\"CleanSerial\", const id)\n\t , (\"CleanSnappy\", const id)\n\t , (\"CleanTypeUnifier\", const id)\n\t , (\"Cloogle\", const id)\n\t , (\"Directory\", const id)\n\t , (\"Dynamics\", const id)\n\t , (\"Gast\", const id)\n\t , (\"Generics\", const id)\n\t , (\"GraphCopy\", const id)\n\t , (\"MersenneTwister\", const id)\n\t , (\"ObjectIO\", \\s me -> {me & me_is_core=not (startsWith \"Std\" s)})\n\t , (\"Platform\", const id)\n\t , (\"Sapl\", const id)\n\t , (\"SoccerFun\", const \\me -> {me & me_is_app=True})\n\t , (\"StdEnv\", const id)\n\t , (\"StdLib\", const id)\n\t , (\"TCPIP\", const id)\n\t , (\"iTasks\", const id)\n\t , (\"clean-compiler\", const \\me -> {me & me_is_app=True})\n\t , (\"clean-ide\", const \\me -> {me & me_is_app=True})\n\t , (\"libcloogle\", const id)\n\t ]\n\t , exclude = [ \"StdEnv\/_startup\"\n\t , \"StdEnv\/_system\"\n\t , \"Platform\/Deprecated\"\n\t , \"Platform\/Data\/Graph\/Inductive\/Query\"\n\t , \"SoccerFun\/RefereeCoach_\"\n\t , \"SoccerFun\/Team_\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > types.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart :: *World -> *World\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (modss, w) = mapSt (flip (uncurry $ findModules cli.exclude cli.root) \"\") cli.libs w\n\t# mods = flatten modss\n\t#! (db, w) = loop cli.root mods newTemporaryDb w\n\t#! db = finaliseDb builtins db\n\t#! db = syncDB 2 db\n\t#! (db,err) = printStats db stderr\n\t#! (ok1,w) = fclose err w\n\t#! (db,f) = saveDB db f\n\t#! (ok2,w) = fclose f w\n\t#! (_,dbg,w) = fopen \"typetree.dot\" FWriteText w\n\t#! (db,dbg) = writeTypeTree db dbg\n\t#! (_,w) = fclose dbg w\n\t= (ok1 && ok2,w)\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: String [(String,String,String ModuleEntry -> ModuleEntry)] !TemporaryDB !*World -> *(!TemporaryDB, !*World)\n\tloop _ [] db w = (db,w)\n\tloop root [(lib,mod,modf):list] db w\n\t#! w = snd (fclose (stderr <<< lib <<< \": \" <<< mod <<< \"\\n\") w)\n\t#! (db, w) = indexModule False root mod lib modf db w\n\t#! db = eval_all_nodes db\n\t= loop root list db w\n\n\tbuiltins =\n\t\tmap FunctionEntry builtin_functions ++\n\t\tmap ClassEntry builtin_classes ++\n\t\tmap TypeDefEntry builtin_types ++\n\t\tmap FunctionEntry (concatMap constructor_functions builtin_types) ++\n\t\tmap FunctionEntry (concatMap record_functions builtin_types) ++\n\t\tmap SyntaxEntry builtin_syntax\n\n\teval_all_nodes :: !.a -> .a \/\/ From GraphCopy\n\teval_all_nodes g = code {\n\t\tpush_a 0\n\t\t.d 1 0\n\t\tjsr\t_eval_to_nf\n\t\t.o 0 0\n\t}\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[(x,const id):c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\tprintStats :: !*CloogleDB !*File -> *(*CloogleDB, *File)\n\tprintStats db f\n\t# (s,db) = dbStats db\n\t= (db, f\n\t\t<<< \"+-------------------+-------+\\n\"\n\t\t<< \"Modules\" <-- s.n_modules\n\t\t<< \"Functions\" <-- s.n_functions\n\t\t<< \"With types\" <-- s.n_functions_with_type\n\t\t<< \"Unique types\" <-- s.n_unique_types\n\t\t<< \"Type tree depth\" <-- s.type_tree_depth\n\t\t<< \"Type definitions\" <-- s.n_type_definitions\n\t\t<< \"Classes\" <-- s.n_classes\n\t\t<< \"Instances\" <-- s.n_instances\n\t\t<< \"Derivations\" <-- s.n_derivations\n\t\t<< \"Syntax constructs\" <-- s.n_syntax_constructs\n\t\t<<< \"+-------------------+-------+\\n\")\n\twhere\n\t\t(<<) infixl :: *File String -> *File\n\t\t(<<) f s = f <<< \"| \" <<< rpad 17 s <<< \" | \"\n\n\t\t(<--) infixl :: *File Int -> *File\n\t\t(<--) f i = f <<< lpad 5 i <<< \" |\\n\"\n\n\t\tlpad n s = {' ' \\\\ _ <- [0..n-size (toString s)-1]} +++ toString s\n\t\trpad n s = toString s +++ {' ' \\\\ _ <- [0..n-size (toString s)-1]}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"912ef6a168bffb11ff4f85cee3761dce3fa34eaf","subject":"Don't search macros and typedefs when unify is present","message":"Don't search macros and typedefs when unify is present\n","repos":"clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/CloogleServer.icl","new_file":"backend\/CloogleServer.icl","new_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , libraries :: Maybe ([String], Bool)\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , dcl_line :: Maybe Int\n , distance :: Int\n , builtin :: Maybe Bool\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , recordfield_of :: Maybe String\n , generic_derivations :: Maybe [(String, [(String,String,Maybe Int)])]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [(String, [(String,String,Maybe Int)])]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , libraries = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_INVALIDNAME \"function name too long\", w)\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= (err E_INVALIDNAME \"name cannot contain spaces\", w)\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= (err E_INVALIDTYPE \"couldn't parse type\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= map (uncurry (makeTypeResult (Just typeName))) types\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case (isNothing mbType,name) of\n\t\t\t(True,Just n) = findMacro` (\\loc _ -> isNameMatch (size n-2) n loc) db\n\t\t\t_ = []\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _) _ _ f _ -> isNameMatch\n\t\t (size n-2) n (Location lib mod Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case (isNothing mbType,lcName) of\n\t\t\t(True,Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\t_ = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\(Location _ _ _ c`) _ _ _ -> toLowerCase c` == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult (Location lib mod line cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [(concat (print False t), map loc ls) \\\\ (t,ls) <- getInstances cls db]\n\t\t }\n\t\t )\n\twhere\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef -> Result\n\tmakeTypeResult mbName (Location lib mod line t) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,builtin) = case fl of\n\t\t\t(Location l m ln f) = (l, m, f, ln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein a b\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> (String, String, Maybe Int)\n\tloc (Location lib mod ln _) = (lib, mod, ln)\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg +\n\t\t\tif (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\" + \")\\n\"\n\tmsgToString _ _ = \"\"\n","old_contents":"module CloogleServer\n\nimport StdArray, StdBool, StdFile, StdList, StdOrdList, StdOverloaded, StdTuple\nfrom StdFunc import o, flip, const\nfrom StdMisc import abort\n\nfrom TCPIP import :: IPAddress, :: Port, instance toString IPAddress\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport System.CommandLine\nimport Text.JSON\nimport Data.Functor\nimport Control.Applicative\nimport Control.Monad\nfrom Text import class Text(concat,trim,indexOf,toLowerCase),\n\tinstance Text String, instance + String\n\nimport System.Time\n\nimport qualified StdMaybe as OldMaybe\nfrom SimpleTCPServer import :: LogMessage{..}, serve, :: Logger\nimport qualified SimpleTCPServer\nimport TypeDB\nimport Type\nimport Levenshtein\n\n:: OldMaybe a :== 'SimpleTCPServer'.Maybe a\n\n:: Request = { unify :: Maybe String\n , name :: Maybe String\n , className :: Maybe String\n , typeName :: Maybe String\n , modules :: Maybe [String]\n , libraries :: Maybe ([String], Bool)\n , page :: Maybe Int\n }\n\n:: Response = { return :: Int\n , data :: [Result]\n , msg :: String\n , more_available :: Maybe Int\n , suggestions :: Maybe [(Request, Int)]\n }\n\n:: Result = FunctionResult FunctionResult\n | TypeResult TypeResult\n | ClassResult ClassResult\n | MacroResult MacroResult\n\n:: BasicResult = { library :: String\n , filename :: String\n , modul :: String\n , dcl_line :: Maybe Int\n , distance :: Int\n , builtin :: Maybe Bool\n }\n\n:: FunctionResult :== (BasicResult, FunctionResultExtras)\n:: FunctionResultExtras = { func :: String\n , unifier :: Maybe StrUnifier\n , cls :: Maybe ShortClassResult\n , constructor_of :: Maybe String\n , recordfield_of :: Maybe String\n , generic_derivations :: Maybe [(String, [(String,String,Maybe Int)])]\n }\n\n:: TypeResult :== (BasicResult, TypeResultExtras)\n:: TypeResultExtras = { type :: String\n }\n\n:: ClassResult :== (BasicResult, ClassResultExtras)\n:: ClassResultExtras = { class_name :: String\n , class_heading :: String\n , class_funs :: [String]\n , class_instances :: [(String, [(String,String,Maybe Int)])]\n }\n\n:: MacroResult :== (BasicResult, MacroResultExtras)\n:: MacroResultExtras = { macro_name :: String\n , macro_representation :: String\n }\n\n:: StrUnifier :== ([(String,String)], [(String,String)])\n\n:: ErrorResult = Error Int String\n\n:: ShortClassResult = { cls_name :: String, cls_vars :: [String] }\n\nderive JSONEncode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\nderive JSONDecode Request, Response, Result, ShortClassResult, BasicResult,\n\tFunctionResultExtras, TypeResultExtras, ClassResultExtras, MacroResultExtras\n\ninstance zero Request\nwhere\n\tzero = { unify = Nothing\n\t , name = Nothing\n\t , className = Nothing\n\t , typeName = Nothing\n\t , modules = Nothing\n\t , libraries = Nothing\n\t , page = Nothing\n\t }\n\ninstance toString Response where toString r = toString (toJSON r) + \"\\n\"\ninstance toString Request where toString r = toString $ toJSON r\n\ninstance fromString (Maybe Request) where fromString s = fromJSON $ fromString s\n\ninstance < BasicResult where (<) r1 r2 = r1.distance < r2.distance\ninstance < Result\nwhere\n\t(<) r1 r2 = basic r1 < basic r2\n\twhere\n\t\tbasic :: Result -> BasicResult\n\t\tbasic (FunctionResult (br,_)) = br\n\t\tbasic (TypeResult (br,_)) = br\n\t\tbasic (ClassResult (br,_)) = br\n\t\tbasic (MacroResult (br,_)) = br\n\nerr :: Int String -> Response\nerr c m = { return = c\n , data = []\n , msg = m\n , more_available = Nothing\n , suggestions = Nothing\n }\n\nE_NORESULTS :== 127\nE_INVALIDINPUT :== 128\nE_INVALIDNAME :== 129\nE_INVALIDTYPE :== 130\n\nMAX_RESULTS :== 15\n\nStart w\n# (io, w) = stdio w\n# (cmdline, w) = getCommandLine w\n| length cmdline <> 2 = help io w\n# [_,port:_] = cmdline\n# port = toInt port\n# (db, io) = openDb io\n# (_, w) = fclose io w\n| isNothing db = abort \"stdin does not have a TypeDB\\n\"\n#! db = fromJust db\n= serve (handle db) ('OldMaybe'.Just log) port w\nwhere\n\thelp :: *File *World -> *World\n\thelp io w\n\t# io = io <<< \"Usage: .\/CloogleServer \\n\"\n\t= snd $ fclose io w\n\n\thandle :: !TypeDB !(Maybe Request) !*World -> *(!Response, !*World)\n\thandle _ Nothing w = (err E_INVALIDINPUT \"Couldn't parse input\", w)\n\thandle db (Just request=:{unify,name,page}) w\n\t\t| isJust name && size (fromJust name) > 40\n\t\t\t= (err E_INVALIDNAME \"function name too long\", w)\n\t\t| isJust name && any isSpace (fromString $ fromJust name)\n\t\t\t= (err E_INVALIDNAME \"name cannot contain spaces\", w)\n\t\t| isJust unify && isNothing (parseType $ fromString $ fromJust unify)\n\t\t\t= (err E_INVALIDTYPE \"couldn't parse type\", w)\n\t\t\/\/ Results\n\t\t# drop_n = fromJust (page <|> pure 0) * MAX_RESULTS\n\t\t# results = drop drop_n $ sort $ search request db\n\t\t# more = max 0 (length results - MAX_RESULTS)\n\t\t\/\/ Suggestions\n\t\t# mbType = unify >>= parseType o fromString\n\t\t# suggestions\n\t\t\t= sortBy (\\a b -> snd a > snd b) <$>\n\t\t\t filter ((<)(length results) o snd) <$>\n\t\t\t (mbType >>= \\t -> suggs name t db)\n\t\t# results = take MAX_RESULTS results\n\t\t\/\/ Response\n\t\t| isEmpty results = (err E_NORESULTS \"No results\", w)\n\t\t= ( { return = 0\n\t\t , msg = \"Success\"\n\t\t , data = results\n\t\t , more_available = Just more\n\t\t , suggestions = suggestions\n\t\t }\n\t\t , w)\n\n\tsuggs :: !(Maybe String) !Type !TypeDB -> Maybe [(Request, Int)]\n\tsuggs n (Func is r cc) db\n\t\t| length is < 3\n\t\t\t= Just [let t` = concat $ print False $ Func is` r cc in\n\t\t\t let request = {zero & name=n, unify=Just t`} in\n\t\t\t (request, length $ search request db)\n\t\t\t \\\\ is` <- permutations is | is` <> is]\n\tsuggs _ _ _ = Nothing\n\n\tsearch :: !Request !TypeDB -> [Result]\n\tsearch {unify,name,className,typeName,modules,libraries,page} db\n\t\t# db = case libraries of\n\t\t\t(Just ls) = filterLocations (isLibMatch ls) db\n\t\t\tNothing = db\n\t\t# db = case modules of\n\t\t\t(Just ms) = filterLocations (isModMatch ms) db\n\t\t\tNothing = db\n\t\t| isJust className\n\t\t\t# className = fromJust className\n\t\t\t# classes = findClass className db\n\t\t\t= map (flip makeClassResult db) classes\n\t\t| isJust typeName\n\t\t\t# typeName = fromJust typeName\n\t\t\t# types = findType typeName db\n\t\t\t= map (uncurry (makeTypeResult (Just typeName))) types\n\t\t# mbType = prepare_unification True <$> (unify >>= parseType o fromString)\n\t\t\/\/ Search normal functions\n\t\t# filts = catMaybes [ (\\t _ -> isUnifiable t) <$> mbType\n\t\t , (\\n loc _ -> isNameMatch (size n-2) n loc) <$> name\n\t\t ]\n\t\t# funs = map (\\f -> makeFunctionResult name mbType Nothing f db) $ findFunction`` filts db\n\t\t\/\/ Search macros\n\t\t# macros = case name of\n\t\t\tNothing = []\n\t\t\t(Just n) = findMacro` (\\loc _ -> isNameMatch (size n-2) n loc) db\n\t\t# macros = map (\\(lhs,rhs) -> makeMacroResult name lhs rhs) macros\n\t\t\/\/ Search class members\n\t\t# filts = catMaybes [ (\\t _ _ _ _->isUnifiable t) <$> mbType\n\t\t , (\\n (Location lib mod _ _) _ _ f _ -> isNameMatch\n\t\t (size n-2) n (Location lib mod Nothing f)) <$> name\n\t\t ]\n\t\t# members = findClassMembers`` filts db\n\t\t# members = map (\\(Location lib mod line cls,vs,_,f,et) -> makeFunctionResult name mbType\n\t\t\t(Just {cls_name=cls,cls_vars=vs}) (Location lib mod line f,et) db) members\n\t\t\/\/ Search types\n\t\t# lcName = if (isJust mbType && isType (fromJust mbType))\n\t\t\t(let (Type name _) = fromJust mbType in Just $ toLowerCase name)\n\t\t\t(toLowerCase <$> name)\n\t\t# types = case lcName of\n\t\t\t(Just n) = findType` (\\loc _ -> toLowerCase (getName loc) == n) db\n\t\t\tNothing = []\n\t\t# types = map (\\(tl,td) -> makeTypeResult name tl td) types\n\t\t\/\/ Search classes\n\t\t# classes = case (isNothing mbType, toLowerCase <$> name) of\n\t\t\t(True, Just c) = findClass` (\\(Location _ _ _ c`) _ _ _ -> toLowerCase c` == c) db\n\t\t\t_ = []\n\t\t# classes = map (flip makeClassResult db) classes\n\t\t\/\/ Merge results\n\t\t= sort $ funs ++ members ++ types ++ classes ++ macros\n\n\tmakeClassResult :: (Location, [TypeVar], ClassContext, [(Name,ExtendedType)])\n\t\tTypeDB -> Result\n\tmakeClassResult (Location lib mod line cls, vars, cc, funs) db\n\t\t= ClassResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = -100\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { class_name = cls\n\t\t , class_heading = foldl ((+) o (flip (+) \" \")) cls vars +\n\t\t if (isEmpty cc) \"\" \" \" + concat (print False cc)\n\t\t , class_funs = [print_fun fun \\\\ fun <- funs]\n\t\t , class_instances\n\t\t = sortBy (\\(a,_) (b,_) -> a < b)\n\t\t [(concat (print False t), map loc ls) \\\\ (t,ls) <- getInstances cls db]\n\t\t }\n\t\t )\n\twhere\n\t\tprint_fun :: (Name,ExtendedType) -> String\n\t\tprint_fun f=:(_,ET _ et) = fromJust $\n\t\t\tet.te_representation <|> (pure $ concat $ print False f)\n\n\tmakeTypeResult :: (Maybe String) Location TypeDef -> Result\n\tmakeTypeResult mbName (Location lib mod line t) td\n\t\t= TypeResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\tmakeTypeResult mbName (Builtin t) td\n\t\t= TypeResult\n\t\t ( { library = \"\"\n\t\t , filename = \"\"\n\t\t , dcl_line = Nothing\n\t\t , modul = \"\"\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` t (fromJust mbName))\n\t\t , builtin = Just True\n\t\t }\n\t\t , { type = concat $ print False td }\n\t\t )\n\n\tmakeMacroResult :: (Maybe String) Location Macro -> Result\n\tmakeMacroResult mbName (Location lib mod line m) mac\n\t\t= MacroResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance\n\t\t = if (isNothing mbName) -100 (levenshtein` (fromJust mbName) m)\n\t\t , builtin = Nothing\n\t\t }\n\t\t , { macro_name = m\n\t\t , macro_representation = mac.macro_as_string\n\t\t }\n\t\t )\n\n\tmakeFunctionResult :: (Maybe String) (Maybe Type) (Maybe ShortClassResult)\n\t\t(Location, ExtendedType) TypeDB -> Result\n\tmakeFunctionResult\n\t\torgsearch orgsearchtype mbCls (fl, et=:(ET type tes)) db\n\t\t= FunctionResult\n\t\t ( { library = lib\n\t\t , filename = modToFilename mod\n\t\t , dcl_line = line\n\t\t , modul = mod\n\t\t , distance = distance\n\t\t , builtin = builtin\n\t\t }\n\t\t , { func = fromJust (tes.te_representation <|>\n\t\t (pure $ concat $ print False (fname,et)))\n\t\t , unifier = toStrUnifier <$> finish_unification <$>\n\t\t (orgsearchtype >>= unify [] (prepare_unification False type))\n\t\t , cls = mbCls\n\t\t , constructor_of = if tes.te_isconstructor\n\t\t (let (Func _ r _) = type in Just $ concat $ print False r)\n\t\t Nothing\n\t\t , recordfield_of = if tes.te_isrecordfield\n\t\t (let (Func [t:_] _ _) = type in Just $ concat $ print False t)\n\t\t Nothing\n\t\t , generic_derivations\n\t\t = let derivs = getDerivations fname db in\n\t\t const (sortBy (\\(a,_) (b,_) -> a < b)\n\t\t\t\t [(concat $ print False d, map loc ls) \\\\ (d,ls) <- derivs]) <$>\n\t\t tes.te_generic_vars\n\t\t }\n\t\t )\n\twhere\n\t\t(lib,mod,fname,line,builtin) = case fl of\n\t\t\t(Location l m ln f) = (l, m, f, ln, Nothing)\n\t\t\t(Builtin f) = (\"\", \"\", f, Nothing, Just True)\n\n\t\ttoStrUnifier :: Unifier -> StrUnifier\n\t\ttoStrUnifier (tvas1, tvas2) = (map toStr tvas1, map toStr tvas2)\n\t\twhere toStr (var, type) = (var, concat $ print False type)\n\n\t\ttoStrPriority :: (Maybe TE_Priority) -> String\n\t\ttoStrPriority p = case print False p of [] = \"\"; ss = concat [\" \":ss]\n\n\t\tdistance\n\t\t\t| isNothing orgsearch || fromJust orgsearch == \"\"\n\t\t\t\t| isNothing orgsearchtype = 0\n\t\t\t\t# orgsearchtype = fromJust orgsearchtype\n\t\t\t\t# (Just (ass1, ass2)) = finish_unification <$>\n\t\t\t\t\tunify [] orgsearchtype (prepare_unification False type)\n\t\t\t\t= penalty + toInt (sum [typeComplexity t \\\\ (_,t)<-ass1 ++ ass2 | not (isVar t)])\n\t\t\t# orgsearch = fromJust orgsearch\n\t\t\t= penalty + levenshtein` orgsearch fname\n\t\twhere\n\t\t\tpenalty\n\t\t\t| tes.te_isrecordfield = 2\n\t\t\t| tes.te_isconstructor = 1\n\t\t\t| otherwise = 0\n\n\t\t\ttypeComplexity :: Type -> Real\n\t\t\ttypeComplexity (Type _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Func is r _) = 2.0 * foldr ((+) o typeComplexity) 1.0 [r:is]\n\t\t\ttypeComplexity (Var _) = 1.0\n\t\t\ttypeComplexity (Cons _ ts) = 1.2 * foldr ((+) o typeComplexity) 1.0 ts\n\t\t\ttypeComplexity (Uniq t) = 3.0 + typeComplexity t\n\n\tlevenshtein` :: String String -> Int\n\tlevenshtein` a b = if (indexOf a b == -1) 0 -100 + levenshtein a b\n\n\tmodToFilename :: String -> String\n\tmodToFilename mod = (toString $ reverse $ takeWhile ((<>)'.')\n\t $ reverse $ fromString mod) + \".dcl\"\n\n\tisUnifiable :: Type ExtendedType -> Bool\n\tisUnifiable t1 (ET t2 _) = isJust (unify [] t1 (prepare_unification False t2))\n\n\tisNameMatch :: !Int !String Location -> Bool\n\tisNameMatch maxdist n1 loc\n\t\t# (n1, n2) = ({toLower c \\\\ c <-: n1}, {toLower c \\\\ c <-: getName loc})\n\t\t= n1 == \"\" || indexOf n1 n2 <> -1 || levenshtein n1 n2 <= maxdist\n\n\tisModMatch :: ![String] Location -> Bool\n\tisModMatch mods (Location _ mod _ _) = isMember mod mods\n\tisModMatch _ (Builtin _) = False\n\n\tisLibMatch :: (![String], !Bool) Location -> Bool\n\tisLibMatch (libs,_) (Location lib _ _ _) = any (\\l -> indexOf l lib == 0) libs\n\tisLibMatch (_,blti) (Builtin _) = blti\n\n\tloc :: Location -> (String, String, Maybe Int)\n\tloc (Location lib mod ln _) = (lib, mod, ln)\n\n\tlog :: (LogMessage (Maybe Request) Response) IPAddress *World\n\t\t-> *(IPAddress, *World)\n\tlog msg s w\n\t| not needslog = (newS msg s, w)\n\t# (tm,w) = localTime w\n\t# (io,w) = stdio w\n\t# io = io <<< trim (toString tm) <<< \" \" <<< msgToString msg s\n\t= (newS msg s, snd (fclose io w))\n\twhere\n\t\tneedslog = case msg of (Received _) = True; (Sent _) = True; _ = False\n\n\tnewS :: (LogMessage (Maybe Request) Response) IPAddress -> IPAddress\n\tnewS m s = case m of (Connected ip) = ip; _ = s\n\n\tmsgToString :: (LogMessage (Maybe Request) Response) IPAddress -> String\n\tmsgToString (Received Nothing) ip\n\t\t= toString ip + \" <-- Nothing\\n\"\n\tmsgToString (Received (Just a)) ip\n\t\t= toString ip + \" <-- \" + toString a + \"\\n\"\n\tmsgToString (Sent {return,data,msg,more_available}) ip\n\t\t= toString ip + \" --> \" + toString (length data)\n\t\t\t+ \" results (\" + toString return + \"; \" + msg +\n\t\t\tif (isJust more_available) (\"; \" + toString (fromJust more_available) + \" more\") \"\" + \")\\n\"\n\tmsgToString _ _ = \"\"\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"e61557d61120ab6af49cc4f2d7b413eaf7474132","subject":"Slight improvement to #6: delay after sending message","message":"Slight improvement to #6: delay after sending message\n","repos":"clean-cloogle\/clean-irc","old_file":"IRCBot.icl","new_file":"IRCBot.icl","new_contents":"implementation module IRCBot\n\nfrom Data.Func import $\nimport Data.Either\nimport Data.Error\nimport Data.Maybe\nimport IRC\nimport TCPIP\n\nfrom Text import class Text(split,join), instance Text String\n\nimport StdList\nimport StdBool\n\nTIMEOUT :== Just 1000\n\nbot :: (String, Int) [IRCMessage] [IRCMessage] a (IRCMessage a *World -> (Maybe [IRCMessage], a, *World)) *World -> (MaybeErrorString a, *World)\nbot (host, port) start end state bot w\n\/\/Lookup hostname\n# (ip, w) = lookupIPAddress host w\n| isNothing ip = (Error $ \"DNS lookup for \" +++ host +++ \" failed\", w)\n\/\/Connect\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (fromJust ip, port) w\n| rpt == TR_Expired = (Error $ \"Connection to \" +++ host +++ \" timed out\", w)\n| rpt == TR_NoSuccess = (Error $ \"Could not connect to \" +++ host, w)\n\/\/ Send startup commands\n# (merr, chan, w) = send (map toString start) (fromJust chan) w\n| isError merr = (Error $ fromError merr, w)\n\/\/Start processing function\n# (mer, chan, state, w) = process chan \"\" state bot w\n| isError mer = (Error $ fromError mer, w)\n\/\/ Send shutdown commands\n# (merr, {rChannel,sChannel}, w) = send (map toString end) chan w\n| isError merr = (Error $ fromError merr, w)\n\/\/Close channels\n= (Ok state, closeChannel sChannel (closeRChannel rChannel w))\n\nimport StdDebug,StdMisc\nprocess :: TCP_DuplexChannel String a (IRCMessage a *World -> (Maybe [IRCMessage], a, *World)) *World -> (MaybeErrorString (), TCP_DuplexChannel, a, *World)\nprocess chan acc state bot w\n\/\/See if we have a message\n= case split \"\\r\\n\" acc of\n\t\/\/We only have one message that is not complete\n\t[m] \n\t\t\/\/Receive\n\t\t# (merr_resp, chan, w) = recv chan w\n\t\t| isError merr_resp = (Error (fromError merr_resp), chan, state, w)\n\t\t# (Ok mresp) = merr_resp\n\t\t| isNothing mresp = process chan acc state bot w\n\t\t= process chan (m +++ fromJust mresp) state bot w\n\t\/\/We have a successfull split and therefore we process at least one message\n\t[m:xs]\n\t\t# acc = join \"\\r\\n\" xs\n\t\t| not (trace_tn $ \"Full message: '\" +++ m +++ \"'\") = undef\n\t\t= case parseIRCMessage $ m +++ \"\\r\\n\" of\n\t\t\t(Left err) = (Error $ \"IRC Parsing error: \" +++ join \"\\n\" err, chan, state, w)\n\t\t\t(Right msg)\n\t\t\t# (mircc, state, w) = bot msg state w\n\t\t\t| isNothing mircc = (Ok (), chan, state, w) \/\/ Bot asks to quit\n\t\t\t\/\/Possible send the commands\n\t\t\t# (merr, chan, w) = send (map toString $ fromJust mircc) chan w\n\t\t\t| isError merr = (Error $ fromError merr, chan, state, w)\n\t\t\t\/\/Recurse\n\t\t\t= process chan acc state bot w\n\nsend :: ![String] !TCP_DuplexChannel !*World -> (!MaybeErrorString (), !TCP_DuplexChannel, !*World)\nsend [] chan w = (Ok (), chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = (Error \"Could not send message\", {sChannel=sChannel,rChannel=rChannel}, w)\n# (_, w) = sleep 500000 w\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\twhere\n\t\tsleep :: !Int !*World -> (!Int, *World)\n\t\tsleep i w = code {\n\t\t\t\tccall usleep \"I:I:A\"\n\t\t\t}\n\nrecv :: TCP_DuplexChannel *World -> (MaybeErrorString (Maybe String), TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Ok Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = (Error \"Timeout recv fail\", {sChannel=sChannel,rChannel=rChannel}, w)\n= (Ok $ Just $ toString $ fromJust resp, {sChannel=sChannel,rChannel=rChannel}, w)\n","old_contents":"implementation module IRCBot\n\nfrom Data.Func import $\nimport Data.Either\nimport Data.Error\nimport Data.Maybe\nimport IRC\nimport TCPIP\n\nfrom Text import class Text(split,join), instance Text String\n\nimport StdList\nimport StdBool\n\nTIMEOUT :== Just 1000\n\nbot :: (String, Int) [IRCMessage] [IRCMessage] a (IRCMessage a *World -> (Maybe [IRCMessage], a, *World)) *World -> (MaybeErrorString a, *World)\nbot (host, port) start end state bot w\n\/\/Lookup hostname\n# (ip, w) = lookupIPAddress host w\n| isNothing ip = (Error $ \"DNS lookup for \" +++ host +++ \" failed\", w)\n\/\/Connect\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (fromJust ip, port) w\n| rpt == TR_Expired = (Error $ \"Connection to \" +++ host +++ \" timed out\", w)\n| rpt == TR_NoSuccess = (Error $ \"Could not connect to \" +++ host, w)\n\/\/ Send startup commands\n# (merr, chan, w) = send (map toString start) (fromJust chan) w\n| isError merr = (Error $ fromError merr, w)\n\/\/Start processing function\n# (mer, chan, state, w) = process chan \"\" state bot w\n| isError mer = (Error $ fromError mer, w)\n\/\/ Send shutdown commands\n# (merr, {rChannel,sChannel}, w) = send (map toString end) chan w\n| isError merr = (Error $ fromError merr, w)\n\/\/Close channels\n= (Ok state, closeChannel sChannel (closeRChannel rChannel w))\n\nimport StdDebug,StdMisc\nprocess :: TCP_DuplexChannel String a (IRCMessage a *World -> (Maybe [IRCMessage], a, *World)) *World -> (MaybeErrorString (), TCP_DuplexChannel, a, *World)\nprocess chan acc state bot w\n\/\/See if we have a message\n= case split \"\\r\\n\" acc of\n\t\/\/We only have one message that is not complete\n\t[m] \n\t\t\/\/Receive\n\t\t# (merr_resp, chan, w) = recv chan w\n\t\t| isError merr_resp = (Error (fromError merr_resp), chan, state, w)\n\t\t# (Ok mresp) = merr_resp\n\t\t| isNothing mresp = process chan acc state bot w\n\t\t= process chan (m +++ fromJust mresp) state bot w\n\t\/\/We have a successfull split and therefore we process at least one message\n\t[m:xs]\n\t\t# acc = join \"\\r\\n\" xs\n\t\t| not (trace_tn $ \"Full message: '\" +++ m +++ \"'\") = undef\n\t\t= case parseIRCMessage $ m +++ \"\\r\\n\" of\n\t\t\t(Left err) = (Error $ \"IRC Parsing error: \" +++ join \"\\n\" err, chan, state, w)\n\t\t\t(Right msg)\n\t\t\t# (mircc, state, w) = bot msg state w\n\t\t\t| isNothing mircc = (Ok (), chan, state, w) \/\/ Bot asks to quit\n\t\t\t\/\/Possible send the commands\n\t\t\t# (merr, chan, w) = send (map toString $ fromJust mircc) chan w\n\t\t\t| isError merr = (Error $ fromError merr, chan, state, w)\n\t\t\t\/\/Recurse\n\t\t\t= process chan acc state bot w\n\nsend :: [String] TCP_DuplexChannel *World -> (MaybeErrorString (), TCP_DuplexChannel, *World)\nsend [] chan w = (Ok (), chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (_, w) = sleep 500000 w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = (Error \"Could not send message\", {sChannel=sChannel,rChannel=rChannel}, w)\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\twhere\n\t\tsleep :: !Int !*World -> (!Int, *World)\n\t\tsleep i w = code {\n\t\t\t\tccall usleep \"I:I:A\"\n\t\t\t}\n\nrecv :: TCP_DuplexChannel *World -> (MaybeErrorString (Maybe String), TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Ok Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = (Error \"Timeout recv fail\", {sChannel=sChannel,rChannel=rChannel}, w)\n= (Ok $ Just $ toString $ fromJust resp, {sChannel=sChannel,rChannel=rChannel}, w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"c9177127684d247309b96d62b6dbee38c8d734f3","subject":"Add documentation for array comprehensions, code cleanup","message":"Add documentation for array comprehensions, code cleanup\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \".\", \"%:\", \"[*<=*]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i\\\\i<-[0,2..9] } \/\/ Fancy things can be done if you combine this with a {{ZF}}. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \".\", \"%:\", \"[*<=*]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i\\\\i<-[0,2..9] } \/\/ Fancy things can be done if you combine this with a {{ZF}}. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code =\n\t\t[\"[... \\\\\\\\ ... <- ...]\"\n\t\t,\"{... \\\\\\\\ ... <- ...}\"]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"5f7f893dafaac31527e1b233e866f7cfa2c6bc90","subject":"Return syntax result for \/comments?\/","message":"Return syntax result for \/comments?\/\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_basicvalues\n\t, bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_basicvalues =\n\t{ syntax_title = \"basic values\"\n\t, syntax_patterns = map exact [\"'.'\", \"[+-]?\\\\d+\", \"[+-]?0[0-7]+\", \"[-+]?0x[0-9a-fA-F]+\", \"E\"]\n\t, syntax_code = [\"0x...\", \"0...\", \"'...'\", \"...E...\"]\n\t, syntax_description =\n\t\t\"Constant basic values can be of type {{`Int`}}, {{`Char`}} and {{`Real`}}. See also {{`Bool`}}.\\n\\n\" +\n\t\t\"Integers can be specified in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix) notation.\\n\\n\" +\n\t\t\"Characters can either be printable characters (except `'`) or an escape sequence.\\n\" +\n\t\t\"An escape sequence is a character escape, a hexademical escape (starting with `x`), an octal escape (starting with `0` to `7`) or a decimal escape (starting with `d`).\\n\\n\" +\n\t\t\"Reals can be suffixed by a power of ten in the scientific notation.\\n\\n\" +\n\t\t\"Basic values can also be pattern matched with these notations.\"\n\t, syntax_doc_locations = [CLR 6 \"4.1.1\" \"_Toc311798017\"]\n\t, syntax_examples = map (EXs \"rhs\")\n\t\t[ \"(42, -42, +42) \/\/ Tuple with 42, -42 and 42 in decimal notation\"\n\t\t, \"(052, -052, +052) \/\/ Tuple with 42, -42 and 42 in octal notation\"\n\t\t, \"(0x2a, -0x2a, +0x2A) \/\/ Tuple with 42, -42 and 42 in hexadecimal notation\"\n\t\t, \"('a', '\\\\x2a', '\\\\052') \/\/ Tuple with a normal character and twice the character with ASCII value 42\"\n\t\t, \"['\\\\n', '\\\\r', '\\\\f', '\\\\b', '\\\\t', '\\\\v', '\\\\', '\\\\'', '\\\\\\\"']\\n\" +\n\t\t \" \/\/ All character escapes\"\n\t\t, \"(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\\n\" +\n\t\t \" \/\/ Several reals\"\n\t\t]\n\t}\n\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\", \"comments?\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... [| ...] :: ... \", \"derive ... ... [of ...] [with ...]\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples = map EX\n\t\t[ \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, \"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context. The context will become an argument.\\n\" +\n\t\t \"derive gFun CONS of {gcd_arity} with f _ \/\/ A derivation that does not use all arguments. The ompiler can optimize even more\\n\" +\n\t\t \"gFun{|CONS of {gcd_arity}|} f _ = \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t, \"abc ['abc':rest] = True \/\/ The special syntax can als be used to patternmatch\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_basicvalues\n\t, bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_basicvalues =\n\t{ syntax_title = \"basic values\"\n\t, syntax_patterns = map exact [\"'.'\", \"[+-]?\\\\d+\", \"[+-]?0[0-7]+\", \"[-+]?0x[0-9a-fA-F]+\", \"E\"]\n\t, syntax_code = [\"0x...\", \"0...\", \"'...'\", \"...E...\"]\n\t, syntax_description =\n\t\t\"Constant basic values can be of type {{`Int`}}, {{`Char`}} and {{`Real`}}. See also {{`Bool`}}.\\n\\n\" +\n\t\t\"Integers can be specified in decimal (default), octal (`0` prefix) or hexadecimal (`0x` prefix) notation.\\n\\n\" +\n\t\t\"Characters can either be printable characters (except `'`) or an escape sequence.\\n\" +\n\t\t\"An escape sequence is a character escape, a hexademical escape (starting with `x`), an octal escape (starting with `0` to `7`) or a decimal escape (starting with `d`).\\n\\n\" +\n\t\t\"Reals can be suffixed by a power of ten in the scientific notation.\\n\\n\" +\n\t\t\"Basic values can also be pattern matched with these notations.\"\n\t, syntax_doc_locations = [CLR 6 \"4.1.1\" \"_Toc311798017\"]\n\t, syntax_examples = map (EXs \"rhs\")\n\t\t[ \"(42, -42, +42) \/\/ Tuple with 42, -42 and 42 in decimal notation\"\n\t\t, \"(052, -052, +052) \/\/ Tuple with 42, -42 and 42 in octal notation\"\n\t\t, \"(0x2a, -0x2a, +0x2A) \/\/ Tuple with 42, -42 and 42 in hexadecimal notation\"\n\t\t, \"('a', '\\\\x2a', '\\\\052') \/\/ Tuple with a normal character and twice the character with ASCII value 42\"\n\t\t, \"['\\\\n', '\\\\r', '\\\\f', '\\\\b', '\\\\t', '\\\\v', '\\\\', '\\\\'', '\\\\\\\"']\\n\" +\n\t\t \" \/\/ All character escapes\"\n\t\t, \"(42.0, -42.0, 42E-10, +42.0E+10, -42.0E10)\\n\" +\n\t\t \" \/\/ Several reals\"\n\t\t]\n\t}\n\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"with\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... [| ...] :: ... \", \"derive ... ... [of ...] [with ...]\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples = map EX\n\t\t[ \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\"\n\t\t, \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t, \"gFun{|CONS of {gcd_arity}|} \/\/ Using a specific field of type information, the compiler will only provide this field which makes it a lot faster\"\n\t\t, \"generic gFun a :: a -> Int | gDefault a \/\/ A generic function with a generic context. The context will become an argument.\\n\" +\n\t\t \"derive gFun CONS of {gcd_arity} with f _ \/\/ A derivation that does not use all arguments. The ompiler can optimize even more\\n\" +\n\t\t \"gFun{|CONS of {gcd_arity}|} f _ = \/\/ A derivation that does not use the context and only one field of the generic type descriptor, the compiler can optimize for this.\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t, \"abc ['abc':rest] = True \/\/ The special syntax can als be used to patternmatch\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"da5cae97314318ecf69bd19cae4e08c9c1a67452","subject":"refine syntax pattern for uniqueness","message":"refine syntax pattern for uniqueness\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \"[\", \"]\", \".\", \":\"]\n\t, syntax_code =\n\t\t[\"*...\"\n\t\t,\". ...\" \n\t\t,\"v:.. | [v ..]\" \n\t, syntax_description = \"Annotates a type with its uniqueness. A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [..]`). Note that when using unique types in a function or an ADT the container must also be unique. e.g. `T = T (Int, *File)` has to be `T = T *(Int, *File)`. Functions have to be split up into arity 1 and the sub functions need to be annotated as well. e.g. `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/World is unique\"\n\t\t, \"f :: .a -> .a \/\/f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \"[\", \"]\", \".\"]\n\t, syntax_code =\n\t\t[\"*...\"\n\t\t,\". ...\" \n\t\t,\"v ... | [v ..]\" \n\t, syntax_description = \"Annotates a type with its uniqueness. A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `| [..]`). Note that when using unique types in a function or an ADT the container must also be unique. e.g. `T = T (Int, *File)` has to be `T = T *(Int, *File)`. Functions have to be split up into arity 1 and the sub functions need to be annotated as well. e.g. `T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/World is unique\"\n\t\t, \"f :: .a -> .a \/\/f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b | [v<=u] \/\/f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"d9cc7b00e734e0adf85f6954e8ec12ec667bb389","subject":"Document guards (#180)","message":"Document guards (#180)\n","repos":"dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = \"Specifies the implementation of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = map exact [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"a363883e1dc5a15211498b2310019507bad1a3e2","subject":"improve help","message":"improve help\n","repos":"clean-cloogle\/clean-irc","old_file":"cloogle.icl","new_file":"cloogle.icl","new_contents":"module cloogle\n\nimport GenPrint\nimport IRC\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nfrom Data.Func import $\nfrom Text import class Text(..), instance Text String\n\nimport TCPIP\n\ncommands :: [String]\ncommands = map toString\n\t[NICK \"clooglebot\"\n\t,USER \"cloogle\" 0 \"Cloogle bot\"\n\t,JOIN [(\"#cloogle\", Nothing)]\n\t]\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nKEY :== \"PRIVMSG #cloogle :!\"\n\nsend :: [String] TCP_DuplexChannel *World -> (TCP_DuplexChannel, *World)\nsend [] chan w = (chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = abort \"Could not send request\\n\"\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\nrecv :: TCP_DuplexChannel *World -> (Maybe String, TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = abort \"Halp?\\n\"\n= (toString <$> resp, {sChannel=sChannel,rChannel=rChannel}, w)\n\nmsg :: (String -> IRCCommands)\nmsg = PRIVMSG \"#cloogle\"\n\nprocess :: *File TCP_DuplexChannel *World -> (*File, TCP_DuplexChannel, *World)\nprocess io chan w \n# (mr, chan, w) = recv chan w\n| isNothing mr = process io chan w\n# resp = fromJust mr\n#! io = io <<< (\"Received: \" +++ resp +++ \"\\n\")\n# ind = indexOf KEY resp\n| ind > 0\n\t# cmd = split \" \" $ rtrim $ subString (ind + size KEY) (size resp) resp\n\t#! io = io <<< (\"Received command: \" +++ printToString cmd +++ \"\\n\")\n\t# toSend = case cmd of\n\t\t[\"stop\":_] = Nothing\n\t\t[\"ping\":_] = Just [msg \"pong\"]\n\t\t[\"help\"] = Just \n\t\t\t[msg \"type !help cmd for command specific help\"\n\t\t\t,msg \"available commands: help, ping\"]\n\t\t[\"help\":c:_] = case c of\n\t\t\t\"help\" = Just [msg \"I will print help text\"] \n\t\t\t\"ping\" = Just [msg \"I will reply with pong\"] \n\t\t\t_ = Just [msg \"Unknown command\"]\n\t\t[c:_] = Just [msg $ join \" \" [\"unknown command: \" , c, \", type !help to get help\"]]\n\t| isNothing toSend = (io, chan, w)\n\t# (chan, w) = send (map toString $ fromJust toSend) chan w\n\t= process io chan w\n| indexOf \"PING :\" resp > 0\n\t# cmd = rtrim $ subString (indexOf \"PING :\" resp + size \"PING :\") (size resp) resp\n\t# (chan, w) = send [toString $ PONG cmd Nothing] chan w\n\t= process io chan w\n= process io chan w\n\nStart :: *World -> *World\nStart w\n# (io, w) = stdio w\n# (ip, w) = lookupIPAddress SERVER w\n| isNothing ip = abort $ \"DNS lookup for \" +++ SERVER +++ \" failed\\n\"\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, 6667) w\n| rpt == TR_Expired = abort $ \"Connection to \" +++ SERVER +++ \" timed out\\n\"\n| rpt == TR_NoSuccess = abort $ \"Could not connect to \" +++ SERVER +++ \"\\n\"\n# chan = fromJust chan\n# (chan, w) = send commands chan w\n# (io, chan, w) = process io chan w\n# ({sChannel,rChannel}, w) = send [toString $ QUIT Nothing] chan w\n# (_, w) = fclose io w\n= closeChannel sChannel (closeRChannel rChannel w)\n","old_contents":"module cloogle\n\nimport GenPrint\nimport IRC\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nfrom Data.Func import $\nfrom Text import class Text(..), instance Text String\n\nimport TCPIP\n\ncommands :: [String]\ncommands = map toString\n\t[NICK \"clooglebot\"\n\t,USER \"cloogle\" 0 \"Cloogle bot\"\n\t,JOIN [(\"#cloogle\", Nothing)]\n\t]\n\nTIMEOUT :== Just 10000\nSERVER :== \"irc.freenode.net\"\n\nKEY :== \"PRIVMSG #cloogle :!\"\n\nsend :: [String] TCP_DuplexChannel *World -> (TCP_DuplexChannel, *World)\nsend [] chan w = (chan, w)\nsend [msg:msgs] {sChannel,rChannel} w\n# (rpt,i,sChannel,w) = send_MT TIMEOUT (toByteSeq msg) sChannel w\n| rpt <> TR_Success = abort \"Could not send request\\n\"\n= send msgs {sChannel=sChannel,rChannel=rChannel} w\n\nrecv :: TCP_DuplexChannel *World -> (Maybe String, TCP_DuplexChannel, *World)\nrecv {sChannel,rChannel} w\n# (rpt, resp, rChannel, w) = receive_MT TIMEOUT rChannel w\n| rpt == TR_Expired = (Nothing, {sChannel=sChannel,rChannel=rChannel}, w)\n| rpt == TR_NoSuccess || isNothing resp = abort \"Halp?\\n\"\n= (toString <$> resp, {sChannel=sChannel,rChannel=rChannel}, w)\n\nmsg :: (String -> IRCCommands)\nmsg = PRIVMSG \"#cloogle\"\n\nprocess :: *File TCP_DuplexChannel *World -> (*File, TCP_DuplexChannel, *World)\nprocess io chan w \n# (mr, chan, w) = recv chan w\n| isNothing mr = process io chan w\n# resp = fromJust mr\n#! io = io <<< (\"Received: \" +++ resp +++ \"\\n\")\n# ind = indexOf KEY resp\n| ind > 0\n\t# cmd = split \" \" $ rtrim $ subString (ind + size KEY) (size resp) resp\n\t#! io = io <<< (\"Received command: \" +++ printToString cmd +++ \"\\n\")\n\t# toSend = case cmd of\n\t\t[\"stop\":_] = Nothing\n\t\t[\"ping\":_] = Just [msg \"pong\"]\n\t\t[\"help\":_] = Just [msg \"not implemented yet\"]\n\t\t[c:_] = Just [msg $ join \" \" [\"unknown command: \" , c, \", type !help to get help\"]]\n\t| isNothing toSend = (io, chan, w)\n\t# (chan, w) = send (map toString $ fromJust toSend) chan w\n\t= process io chan w\n| indexOf \"PING :\" resp > 0\n\t# cmd = rtrim $ subString (indexOf \"PING :\" resp + size \"PING :\") (size resp) resp\n\t# (chan, w) = send [toString $ PONG cmd Nothing] chan w\n\t= process io chan w\n= process io chan w\n\nStart :: *World -> *World\nStart w\n# (io, w) = stdio w\n# (ip, w) = lookupIPAddress SERVER w\n| isNothing ip = abort $ \"DNS lookup for \" +++ SERVER +++ \" failed\\n\"\n# (Just ip) = ip\n# (rpt,chan,w) = connectTCP_MT TIMEOUT (ip, 6667) w\n| rpt == TR_Expired = abort $ \"Connection to \" +++ SERVER +++ \" timed out\\n\"\n| rpt == TR_NoSuccess = abort $ \"Could not connect to \" +++ SERVER +++ \"\\n\"\n# chan = fromJust chan\n# (chan, w) = send commands chan w\n# (io, chan, w) = process io chan w\n# ({sChannel,rChannel}, w) = send [toString $ QUIT Nothing] chan w\n# (_, w) = fclose io w\n= closeChannel sChannel (closeRChannel rChannel w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"ea074e32086e4a5115381a7a82d111b22137a863","subject":"Ensure error exit does not print a message","message":"Ensure error exit does not print a message\n\ngit-svn-id: a20303ca0449e3ef575223833049c5e6a53b9062@647218 13f79535-47bb-0310-9956-ffa450edef68\n","repos":"sgoeschl\/commons-exec,mohanaraosv\/commons-exec,apache\/commons-exec,mohanaraosv\/commons-exec,sgoeschl\/commons-exec,apache\/commons-exec","old_file":"src\/test\/scripts\/error.dcl","new_file":"src\/test\/scripts\/error.dcl","new_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Licensed to the Apache Software Foundation (ASF) under one or more\n$! contributor license agreements. See the NOTICE file distributed with\n$! this work for additional information regarding copyright ownership.\n$! The ASF licenses this file to You under the Apache License, Version 2.0\n$! (the \"License\"); you may not use this file except in compliance with\n$! the License. You may obtain a copy of the License at\n$!\n$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n$!\n$! Unless required by applicable law or agreed to in writing, software\n$! distributed under the License is distributed on an \"AS IS\" BASIS,\n$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n$! See the License for the specific language governing permissions and\n$! limitations under the License.\n$! \n$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! do something and return an error result code\n$!\n$ ENV_VAR=f$trnlnm(\"TEST_ENV_VAR\")\n$ write sys$output \"FOO.''ENV_VAR'.''P1'\"\n$!\n$ exit %x10000002 ! this is an Error, but does not print a message","old_contents":"$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! Licensed to the Apache Software Foundation (ASF) under one or more\n$! contributor license agreements. See the NOTICE file distributed with\n$! this work for additional information regarding copyright ownership.\n$! The ASF licenses this file to You under the Apache License, Version 2.0\n$! (the \"License\"); you may not use this file except in compliance with\n$! the License. You may obtain a copy of the License at\n$!\n$! http:\/\/www.apache.org\/licenses\/LICENSE-2.0\n$!\n$! Unless required by applicable law or agreed to in writing, software\n$! distributed under the License is distributed on an \"AS IS\" BASIS,\n$! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n$! See the License for the specific language governing permissions and\n$! limitations under the License.\n$! \n$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n$!\n$! do something and return an error result code\n$!\n$ ENV_VAR=f$trnlnm(\"TEST_ENV_VAR\")\n$ write sys$output \"FOO.''ENV_VAR'.''P1'\"\n$!\n$ exit 2 ! this is an Error","returncode":0,"stderr":"","license":"apache-2.0","lang":"Clean"} {"commit":"5e10123c682c937518086d40a1890fe6135631fc","subject":"Add documentation for =: as an inline pattern match","message":"Add documentation for =: as an inline pattern match\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs. This can also be used to check if a value (not a function argument) matches a pattern (undocumented and you can not use identifiers). `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t, EX \"isSingleton l = l =: [_] \/\/Match a value with a pattern\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \".\", \"%:\", \"[*<=*]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdList\n\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = [\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\", \"..\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = [\"E\", \"E.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = [\"..\", \"|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"It is not possible to derive functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = [\"A\", \"A.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = [\"generic\", \"derive\", \"of\", \"{|*|}\"] \/\/ This * matches everything, which is intentional\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = [\"lambda\", \"\\\\*\", \"->\", \".\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = [\";\", \"{\", \"}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = [\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = [\"^\", \"a^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_otherwise =\n\t{ syntax_title = \"otherwise\"\n\t, syntax_patterns = [\"otherwise\"]\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_patterns = [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = [\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = [\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = [\".\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = [\"\\\\*\", \".\", \"%:\", \"[*<=*]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = [\"&\", \"{*&*[\\\\e]*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = [\"&\", \"{*&*=*}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = [\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"]\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"747d99d348372cd62ff9362f7b98313eb53c0ea9","subject":"Add ABCInstructionResult and ProblemResult formats","message":"Add ABCInstructionResult and ProblemResult formats\n","repos":"clean-cloogle\/clean-irc","old_file":"cloogleirc.icl","new_file":"cloogleirc.icl","new_contents":"module cloogleirc\n\nimport Cloogle\nimport Text.GenPrint\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nimport Data.Either\nfrom Data.Func import $, mapSt\nfrom Text import class Text(..), instance Text String, instance + String\n\nimport Internet.HTTP\n\nimport Text.GenJSON\n\nimport Text.URI\nimport System.Time\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad(bind), >>=\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport System.CommandLine\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\nimport IRC\nimport IRCBot\n\nimport StdMisc, StdDebug\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# s = if (startsWith \"http:\/\/\" s) s (if (startsWith \"https:\/\/\" s) s (\"http:\/\/\" + s))\n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doHTTPRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} 10000 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\ncloogle :: String *World -> (String, *World)\ncloogle data w\n# (mer, w) = doHTTPRequestFollowRedirects\n\t\t{ newHTTPRequest\n\t\t& req_path = \"\/api.php\"\n\t\t, req_query = \"?str=\" + urlEncode data\n\t\t, req_headers = 'DM'.fromList [(\"User-Agent\", \"cloogle-irc\")]\n\t\t, server_name = \"cloogle.org\"\n\t\t, server_port = 80} 10000 10 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= case fromJSON $ fromString resp.HTTPResponse.rsp_data of\n\tNothing = (\"couldn't parse json\", w)\n\tJust {return=127} = (\"No results for \" + data, w)\n\tJust clr = (\"Results for \" + data + \" -- https:\/\/cloogle.org\/#\" +\n\t\treplaceSubString \"+\" \"%20\" (urlEncode data) + \"\\n\" +\n\t\tprocessResults clr, w)\n\twhere\n\t\tprocessResults :: Response -> String\n\t\tprocessResults resp\n\t\t| resp.return > 127 = \"Failed: return code: \" + toString resp.return + \", \" + resp.msg\n\t\t= join \"\\n\" $ map processResult $ take 3 resp.data\n\t\t\n\t\tprocessResult :: Result -> String\n\t\tprocessResult (FunctionResult (br, {func}))\n\t\t\t= \"Function in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ func\n\t\tprocessResult (TypeResult (br, {type}))\n\t\t\t= \"Type in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ limitResults type\n\t\tprocessResult (ClassResult (br, {class_name,class_funs}))\n\t\t\t= \"Class in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ class_name +++ \" with \"\n\t\t\t\t+++ toString (length class_funs) +++ \" class functions\"\n\t\tprocessResult (ModuleResult (br, _))\n\t\t\t= \"Module in \" +++ br.library +++ \": \" +++ br.modul\n\t\tprocessResult (SyntaxResult (br, re))\n\t\t\t= \"Clean syntax: \" +++ re.syntax_title +++ \"\\n\"\n\t\t\t\t+++ concat (intersperse \"; \" re.syntax_code)\n\t\tprocessResult (ABCInstructionResult (br, re))\n\t\t\t= \"ABC instruction: \" +++ re.abc_instruction\n\t\tprocessResult (ProblemResult pr)\n\t\t\t= \"Common problem: \" +++ pr.problem_title\n\t\t\t\t+++ \"; see https:\/\/github.com\/clean-cloogle\/common-problems\/blob\/master\/\" +++ pr.problem_key +++ \".md\"\n\n\t\tlimitResults :: String -> String\n\t\tlimitResults s\n\t\t# lines = split \"\\n\" s\n\t\t| length lines > 4 = limitResults (join \"\\n\" (take 3 lines) + \"\\n...\")\n\t\t= join \"\\n\" (map maxWidth lines)\n\t\t\n\t\tmaxWidth :: String -> String\n\t\tmaxWidth s = if (size s > 80) (subString 0 77 s + \"...\") s\n\n:: BotSettings =\n\t\t{ bs_nick :: String\n\t\t, bs_nickserv :: Maybe String\n\t\t, bs_autojoin :: [String]\n\t\t, bs_port :: Int\n\t\t, bs_server :: String\n\t\t, bs_strftime :: String\n\t\t}\n\nStart :: *World -> (Maybe String, *World)\nStart w\n# ([cmd:args], w) = getCommandLine w\n# (io, w) = stdio w\n# bs = parseCLI cmd args\n| isError bs\n\t# io = io <<< fromError bs <<< \"\\n\"\n\t= (Nothing, snd $ fclose io w)\n# (Ok bs) = bs\n# (_, w) = fclose io w\n# (merr, _, w) = bot (bs.bs_server, bs.bs_port) (startup bs) shutdown () (process bs.bs_strftime) w\n= (merr, w)\n\twhere\n\t\tparseCLI :: String [String] -> MaybeErrorString BotSettings\n\t\tparseCLI _ [] = Ok\n\t\t\t{ bs_nick = \"clooglebot\"\n\t\t\t, bs_nickserv = Nothing\n\t\t\t, bs_autojoin = []\n\t\t\t, bs_port = 6667\n\t\t\t, bs_server = \"irc.freenode.net\"\n\t\t\t, bs_strftime = \"%s\"\n\t\t\t}\n\t\tparseCLI cmd [a:as]\n\t\t| a == \"-f\" || a == \"--strftime\"\n\t\t\t= arg1 \"--strftime\" as \\a c->{c & bs_strftime=a}\n\t\t| a == \"-n\" || a == \"--nick\"\n\t\t\t= arg1 \"--nick\" as \\a c->{c & bs_nick=a}\n\t\t| a == \"-ns\" || a == \"--nickserv\"\n\t\t\t= arg1 \"--nickserv\" as \\a c->{c & bs_nickserv=Just a}\n\t\t| a == \"-a\" || a == \"--autojoin\"\n\t\t\t= arg1 \"--autojoin\" as \\a c->{c & bs_autojoin=c.bs_autojoin ++ [a]}\n\t\t| a == \"-p\" || a == \"--port\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_port=toInt a}\n\t\t| a == \"-s\" || a == \"--server\"\n\t\t\t= arg1 \"--server\" as \\a c->{c & bs_server=a}\n\t\t| a == \"-h\" || a == \"--help\" = Error $ join \"\\n\" $\n\t\t\t[ \"Usage: \" + cmd + \" [OPTS]\"\n\t\t\t, \"Options:\"\n\t\t\t, \"\\t--strftime\/-f FORMAT strftime format used in the output. default: %s\\n\"\n\t\t\t, \"\\t--nick\/-n NICKNAME Use the given nickname instead of clooglebot\"\n\t\t\t, \"\\t--nickserv\/-ns PW Identify via the given password with NickServ\"\n\t\t\t, \"\\t--port\/-p PORT Use the given port instead of port 6667\"\n\t\t\t, \"\\t--server\/-s SERVER Use the given server instead of irc.freenode.net\"\n\t\t\t, \"\\t--autojoin\/-a CHANNEL Add CHANNEL to the autojoin list. This command \"\n\t\t\t, \"\\t can be called multiple times. Beware that #\"\n\t\t\t, \"\\t has to be escaped in most shells\"\n\t\t\t]\n\t\t= Error $ \"Unknown option: \" +++ a\n\t\twhere\n\t\t\targ1 name [] _ = Error $ name +++ \" requires an argument\"\n\t\t\targ1 name [a:as] f = parseCLI cmd as >>= Ok o f a\n\n\t\tnickserv pw = PRIVMSG (CSepList [\"NickServ\"]) $ \"IDENTIFY \" +++ pw\n\n\t\ttoPrefix c = {irc_prefix=Nothing,irc_command=Right c}\n\n\t\tstartup bs = map toPrefix $\n\t\t\t[ NICK bs.bs_nick Nothing\n\t\t\t, USER \"cloogle\" \"cloogle\" \"cloogle\" \"Cloogle bot\"\n\t\t\t]++ maybe [] (pure o nickserv) bs.bs_nickserv\n\t\t\t ++ if (isEmpty bs.bs_autojoin) []\n\t\t\t\t[JOIN (CSepList bs.bs_autojoin) Nothing]\n\t\tshutdown = map toPrefix [QUIT $ Just \"Bye\"]\n\n\t\tprocess :: String !IRCMessage () !*World -> (Maybe [IRCMessage], (), !*World)\n\t\tprocess strf im _ w\n\t\t# (io ,w) = stdio w\n\t\t# (io, w) = log strf \" (r): \" im (io, w)\n\t\t# (_, w) = fclose io w\n\t\t= case im.irc_command of\n\t\t\tLeft numr = (Just [], (), w)\n\t\t\tRight cmd = case process` im.irc_prefix cmd w of\n\t\t\t\t(Nothing, w) = (Nothing, (), w)\n\t\t\t\t(Just cs, w)\n\t\t\t\t# msgs = map toPrefix cs\n\t\t\t\t= (Just msgs, (), w)\n\n\t\tlog :: String String IRCMessage (!*File, !*World) -> (!*File, !*World)\n\t\tlog strf pref m (io, w)\n\t\t#! (t, w) = localTime w\n\t\t= (io <<< strfTime strf t <<< pref <<< toString m <<< \"\\n\", w)\n\n\t\tprocess` :: (Maybe (Either IRCUser String)) IRCCommand *World -> (Maybe [IRCCommand], *World)\n\t\tprocess` (Just (Left user)) (PRIVMSG t m) w\n\t\t\t| m == \"!restart\" = (Nothing, w)\n\t\t\t| m.[0] == '!'\n\t\t\t\t# (msgs, w) = realProcess (split \" \" $ m % (1, size m)) w\n\t\t\t\t= (Just $ map reply msgs, w)\n\t\t\t| m % (0,4) == \"\\001PING\" = (Just [reply m], w)\n\t\t\t= (Just [], w)\n\t\twhere\n\t\t\treply = case (\\(CSepList [t:_]) -> t.[0]) t of\n\t\t\t\t'#' -> PRIVMSG t\n\t\t\t\t_ -> NOTICE user.irc_nick\n\t\tprocess` _ (PING t mt) w = (Just [PONG t mt], w)\n\t\tprocess` _ _ w = (Just [], w)\n\n\t\trealProcess :: [String] *World -> ([String], *World)\n\t\trealProcess [\"help\",x:xs] w = ((case x of\n\t\t\t\"help\" =\n\t\t\t\t[ \"Usage: !help [ARG]\"\n\t\t\t\t, \"Show this help, or the specific help of the argument\"]\n\t\t\t\"ping\" =\n\t\t\t\t[ \"Usage: !ping [ARG [ARG ...]]\"\n\t\t\t\t, \"Ping the bot, it will pong the arguments back\"]\n\t\t\t\"shorten\" =\n\t\t\t\t[ \"Usage: !shorten URL [URL [URL ...]]\"\n\t\t\t\t, \"Shorten the given urls with the cloo.gl url shortener\"]\n\t\t\t\"query\" =\n\t\t\t\t[ \"Usage: !query QUERY\"\n\t\t\t\t, \"Query QUERY in cloogle and return the results\"]\n\t\t\t\"restart\" =\n\t\t\t\t[ \"Usage: !restart\"\n\t\t\t\t, \"Restart the bot\"]\n\t\t\tx = [\"Unknown command: \" +++ x]\n\t\t\t), w)\n\t\trealProcess [\"help\"] w = (\n\t\t\t[\"Type !help cmd for command specific help\"\n\t\t\t,\"available commands: help, ping, shorten, query, restart\"], w)\n\t\trealProcess [\"ping\":xs] w = ([\"pong \" +++ join \" \" xs], w)\n\t\trealProcess [\"shorten\":xs] w = case xs of\n\t\t\t[] = ([\"shorten requires at least one argument\"], w)\n\t\t\txs = mapSt shorten xs w\n\t\trealProcess [\"query\":xs] w = case xs of\n\t\t\t[] = ([\"query requires one or more arguments\"], w)\n\t\t\txs = appFst (split \"\\n\") $ cloogle (join \" \" xs) w\n\t\trealProcess [\"restart\":_] w = ([\"restart takes no arguments\"], w)\n\t\trealProcess [c:_] w = ([join \" \" [\n\t\t\t\"Unknown cmd: \", c, \", type !help to get help\"]], w)\n","old_contents":"module cloogleirc\n\nimport Cloogle\nimport Text.GenPrint\nimport StdEnv\n\nimport Data.Functor\nimport Data.Maybe\nimport Data.Either\nfrom Data.Func import $, mapSt\nfrom Text import class Text(..), instance Text String, instance + String\n\nimport Internet.HTTP\n\nimport Text.GenJSON\n\nimport Text.URI\nimport System.Time\n\nimport Control.Applicative\nimport qualified Control.Monad as CM\nimport qualified Data.Map as DM\nfrom Control.Monad import class Monad(bind), >>=\nfrom Text.Encodings.UrlEncoding import urlEncode\nimport System.CommandLine\nimport Internet.HTTP\nimport Data.Error\nimport Data.List\nimport Data.Functor\nimport Data.Tuple\n\nimport TCPIP\nimport IRC\nimport IRCBot\n\nimport StdMisc, StdDebug\n\nshorten :: String *World -> (String, *World)\nshorten s w \n# s = if (startsWith \"http:\/\/\" s) s (if (startsWith \"https:\/\/\" s) s (\"http:\/\/\" + s))\n# data = \"type=regular&url=\"+urlEncode s+\"&token=a\"\n# (mer, w) = doHTTPRequest \n\t\t{ newHTTPRequest\n\t\t& req_method = HTTP_POST\n\t\t, req_path = \"\/\"\n\t\t, server_name = \"cloo.gl\"\n\t\t, server_port = 80\n\t\t, req_headers = 'DM'.fromList\n\t\t\t[(\"Content-Type\", \"application\/x-www-form-urlencoded\")\n\t\t\t,(\"Content-Length\", toString $ size data)\n\t\t\t,(\"Accept\", \"*\/*\")]\n\t\t, req_data = data} 10000 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= (resp.rsp_data, w)\n\ncloogle :: String *World -> (String, *World)\ncloogle data w\n# (mer, w) = doHTTPRequestFollowRedirects\n\t\t{ newHTTPRequest\n\t\t& req_path = \"\/api.php\"\n\t\t, req_query = \"?str=\" + urlEncode data\n\t\t, req_headers = 'DM'.fromList [(\"User-Agent\", \"cloogle-irc\")]\n\t\t, server_name = \"cloogle.org\"\n\t\t, server_port = 80} 10000 10 w\n| isError mer = (\"request failed: \" + fromError mer, w)\n# resp = fromOk mer\n= case fromJSON $ fromString resp.HTTPResponse.rsp_data of\n\tNothing = (\"couldn't parse json\", w)\n\tJust {return=127} = (\"No results for \" + data, w)\n\tJust clr = (\"Results for \" + data + \" -- https:\/\/cloogle.org\/#\" +\n\t\treplaceSubString \"+\" \"%20\" (urlEncode data) + \"\\n\" +\n\t\tprocessResults clr, w)\n\twhere\n\t\tprocessResults :: Response -> String\n\t\tprocessResults resp\n\t\t| resp.return > 127 = \"Failed: return code: \" + toString resp.return + \", \" + resp.msg\n\t\t= join \"\\n\" $ map processResult $ take 3 resp.data\n\t\t\n\t\tprocessResult :: Result -> String\n\t\tprocessResult (FunctionResult (br, {func}))\n\t\t\t= \"Function in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ func\n\t\tprocessResult (TypeResult (br, {type}))\n\t\t\t= \"Type in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ limitResults type\n\t\tprocessResult (ClassResult (br, {class_name,class_funs}))\n\t\t\t= \"Class in \" +++ br.library +++ \": \" +++ br.modul +++ \"\\n\" +++ class_name +++ \" with \"\n\t\t\t\t+++ toString (length class_funs) +++ \" class functions\"\n\t\tprocessResult (ModuleResult (br, _))\n\t\t\t= \"Module in \" +++ br.library +++ \": \" +++ br.modul\n\t\tprocessResult (SyntaxResult (br, re))\n\t\t\t= \"Clean syntax: \" +++ re.syntax_title +++ \"\\n\"\n\t\t\t\t+++ concat (intersperse \"; \" re.syntax_code)\n\n\t\tlimitResults :: String -> String\n\t\tlimitResults s\n\t\t# lines = split \"\\n\" s\n\t\t| length lines > 4 = limitResults (join \"\\n\" (take 3 lines) + \"\\n...\")\n\t\t= join \"\\n\" (map maxWidth lines)\n\t\t\n\t\tmaxWidth :: String -> String\n\t\tmaxWidth s = if (size s > 80) (subString 0 77 s + \"...\") s\n\n:: BotSettings =\n\t\t{ bs_nick :: String\n\t\t, bs_nickserv :: Maybe String\n\t\t, bs_autojoin :: [String]\n\t\t, bs_port :: Int\n\t\t, bs_server :: String\n\t\t, bs_strftime :: String\n\t\t}\n\nStart :: *World -> (Maybe String, *World)\nStart w\n# ([cmd:args], w) = getCommandLine w\n# (io, w) = stdio w\n# bs = parseCLI cmd args\n| isError bs\n\t# io = io <<< fromError bs <<< \"\\n\"\n\t= (Nothing, snd $ fclose io w)\n# (Ok bs) = bs\n# (_, w) = fclose io w\n# (merr, _, w) = bot (bs.bs_server, bs.bs_port) (startup bs) shutdown () (process bs.bs_strftime) w\n= (merr, w)\n\twhere\n\t\tparseCLI :: String [String] -> MaybeErrorString BotSettings\n\t\tparseCLI _ [] = Ok\n\t\t\t{ bs_nick = \"clooglebot\"\n\t\t\t, bs_nickserv = Nothing\n\t\t\t, bs_autojoin = []\n\t\t\t, bs_port = 6667\n\t\t\t, bs_server = \"irc.freenode.net\"\n\t\t\t, bs_strftime = \"%s\"\n\t\t\t}\n\t\tparseCLI cmd [a:as]\n\t\t| a == \"-f\" || a == \"--strftime\"\n\t\t\t= arg1 \"--strftime\" as \\a c->{c & bs_strftime=a}\n\t\t| a == \"-n\" || a == \"--nick\"\n\t\t\t= arg1 \"--nick\" as \\a c->{c & bs_nick=a}\n\t\t| a == \"-ns\" || a == \"--nickserv\"\n\t\t\t= arg1 \"--nickserv\" as \\a c->{c & bs_nickserv=Just a}\n\t\t| a == \"-a\" || a == \"--autojoin\"\n\t\t\t= arg1 \"--autojoin\" as \\a c->{c & bs_autojoin=c.bs_autojoin ++ [a]}\n\t\t| a == \"-p\" || a == \"--port\"\n\t\t\t= arg1 \"--port\" as \\a c->{c & bs_port=toInt a}\n\t\t| a == \"-s\" || a == \"--server\"\n\t\t\t= arg1 \"--server\" as \\a c->{c & bs_server=a}\n\t\t| a == \"-h\" || a == \"--help\" = Error $ join \"\\n\" $\n\t\t\t[ \"Usage: \" + cmd + \" [OPTS]\"\n\t\t\t, \"Options:\"\n\t\t\t, \"\\t--strftime\/-f FORMAT strftime format used in the output. default: %s\\n\"\n\t\t\t, \"\\t--nick\/-n NICKNAME Use the given nickname instead of clooglebot\"\n\t\t\t, \"\\t--nickserv\/-ns PW Identify via the given password with NickServ\"\n\t\t\t, \"\\t--port\/-p PORT Use the given port instead of port 6667\"\n\t\t\t, \"\\t--server\/-s SERVER Use the given server instead of irc.freenode.net\"\n\t\t\t, \"\\t--autojoin\/-a CHANNEL Add CHANNEL to the autojoin list. This command \"\n\t\t\t, \"\\t can be called multiple times. Beware that #\"\n\t\t\t, \"\\t has to be escaped in most shells\"\n\t\t\t]\n\t\t= Error $ \"Unknown option: \" +++ a\n\t\twhere\n\t\t\targ1 name [] _ = Error $ name +++ \" requires an argument\"\n\t\t\targ1 name [a:as] f = parseCLI cmd as >>= Ok o f a\n\n\t\tnickserv pw = PRIVMSG (CSepList [\"NickServ\"]) $ \"IDENTIFY \" +++ pw\n\n\t\ttoPrefix c = {irc_prefix=Nothing,irc_command=Right c}\n\n\t\tstartup bs = map toPrefix $\n\t\t\t[ NICK bs.bs_nick Nothing\n\t\t\t, USER \"cloogle\" \"cloogle\" \"cloogle\" \"Cloogle bot\"\n\t\t\t]++ maybe [] (pure o nickserv) bs.bs_nickserv\n\t\t\t ++ if (isEmpty bs.bs_autojoin) []\n\t\t\t\t[JOIN (CSepList bs.bs_autojoin) Nothing]\n\t\tshutdown = map toPrefix [QUIT $ Just \"Bye\"]\n\n\t\tprocess :: String !IRCMessage () !*World -> (Maybe [IRCMessage], (), !*World)\n\t\tprocess strf im _ w\n\t\t# (io ,w) = stdio w\n\t\t# (io, w) = log strf \" (r): \" im (io, w)\n\t\t# (_, w) = fclose io w\n\t\t= case im.irc_command of\n\t\t\tLeft numr = (Just [], (), w)\n\t\t\tRight cmd = case process` im.irc_prefix cmd w of\n\t\t\t\t(Nothing, w) = (Nothing, (), w)\n\t\t\t\t(Just cs, w)\n\t\t\t\t# msgs = map toPrefix cs\n\t\t\t\t= (Just msgs, (), w)\n\n\t\tlog :: String String IRCMessage (!*File, !*World) -> (!*File, !*World)\n\t\tlog strf pref m (io, w)\n\t\t#! (t, w) = localTime w\n\t\t= (io <<< strfTime strf t <<< pref <<< toString m <<< \"\\n\", w)\n\n\t\tprocess` :: (Maybe (Either IRCUser String)) IRCCommand *World -> (Maybe [IRCCommand], *World)\n\t\tprocess` (Just (Left user)) (PRIVMSG t m) w\n\t\t\t| m == \"!restart\" = (Nothing, w)\n\t\t\t| m.[0] == '!'\n\t\t\t\t# (msgs, w) = realProcess (split \" \" $ m % (1, size m)) w\n\t\t\t\t= (Just $ map reply msgs, w)\n\t\t\t| m % (0,4) == \"\\001PING\" = (Just [reply m], w)\n\t\t\t= (Just [], w)\n\t\twhere\n\t\t\treply = case (\\(CSepList [t:_]) -> t.[0]) t of\n\t\t\t\t'#' -> PRIVMSG t\n\t\t\t\t_ -> NOTICE user.irc_nick\n\t\tprocess` _ (PING t mt) w = (Just [PONG t mt], w)\n\t\tprocess` _ _ w = (Just [], w)\n\n\t\trealProcess :: [String] *World -> ([String], *World)\n\t\trealProcess [\"help\",x:xs] w = ((case x of\n\t\t\t\"help\" =\n\t\t\t\t[ \"Usage: !help [ARG]\"\n\t\t\t\t, \"Show this help, or the specific help of the argument\"]\n\t\t\t\"ping\" =\n\t\t\t\t[ \"Usage: !ping [ARG [ARG ...]]\"\n\t\t\t\t, \"Ping the bot, it will pong the arguments back\"]\n\t\t\t\"shorten\" =\n\t\t\t\t[ \"Usage: !shorten URL [URL [URL ...]]\"\n\t\t\t\t, \"Shorten the given urls with the cloo.gl url shortener\"]\n\t\t\t\"query\" =\n\t\t\t\t[ \"Usage: !query QUERY\"\n\t\t\t\t, \"Query QUERY in cloogle and return the results\"]\n\t\t\t\"restart\" =\n\t\t\t\t[ \"Usage: !restart\"\n\t\t\t\t, \"Restart the bot\"]\n\t\t\tx = [\"Unknown command: \" +++ x]\n\t\t\t), w)\n\t\trealProcess [\"help\"] w = (\n\t\t\t[\"Type !help cmd for command specific help\"\n\t\t\t,\"available commands: help, ping, shorten, query, restart\"], w)\n\t\trealProcess [\"ping\":xs] w = ([\"pong \" +++ join \" \" xs], w)\n\t\trealProcess [\"shorten\":xs] w = case xs of\n\t\t\t[] = ([\"shorten requires at least one argument\"], w)\n\t\t\txs = mapSt shorten xs w\n\t\trealProcess [\"query\":xs] w = case xs of\n\t\t\t[] = ([\"query requires one or more arguments\"], w)\n\t\t\txs = appFst (split \"\\n\") $ cloogle (join \" \" xs) w\n\t\trealProcess [\"restart\":_] w = ([\"restart takes no arguments\"], w)\n\t\trealProcess [c:_] w = ([join \" \" [\n\t\t\t\"Unknown cmd: \", c, \", type !help to get help\"]], w)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"51048c97404a7ba0786b0f6964c6d654d0ac316d","subject":"Process reviews","message":"Process reviews\n","repos":"dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle","old_file":"backend\/Builtins.icl","new_file":"backend\/Builtins.icl","new_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [(Location, FunctionEntry)]\nbuiltin_functions\n\t= [ ( Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , {zero & fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []}\n\t )\n\t , ( Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , {zero & fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]}\n\t )\n\t ]\n\nbuiltin_classes :: [(Location, ClassEntry)]\nbuiltin_classes\n\t= [ ( Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , { ce_vars=[\"v\"]\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t }\n\t )\n\t ]\n\nbuiltin_types :: [(Location, TypeDefEntry)]\nbuiltin_types\n\t= [ ( Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , { deft\n\t & tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Int\"})\n\t , ( Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Real\"})\n\t , ( Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Char\"})\n\t , ( Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"String\",\n\t tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], {deft & tde_typedef.td_name = \"Dynamic\"})\n\t , ( Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"File\"})\n\t , ( Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"World\",\n\t tde_typedef.td_uniq = True,\n\t tde_doc = Just $ TypeDoc\n\t (Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\")\n\t [] Nothing})\n\t , ( Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"], {deft & tde_typedef.td_name = \"(->)\",\n\t tde_typedef.td_args = [Var \"a\", Var \"b\"],\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\")\n\t [\"The argument type\", \"The result type\"]\n\t Nothing})\n\t , ( Builtin \"()\" [], {deft & tde_typedef.td_name=\"_Unit\",\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The void \/ unit type.\")\n\t [] Nothing,\n\t tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]})\n\t : lists\n\t ++ arrays\n\t ++ tuples\n\t ]\nwhere\n\tdeft = {tde_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract Nothing}, tde_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> (Location, TypeDefEntry)\n\t\tmake_list k s = (Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description)\n\t\t\t\t[\"The type of the list elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> (Location, TypeDefEntry)\n\t\tmake_array k = (Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description)\n\t\t\t\t[\"The type of the array elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> (Location, TypeDefEntry)\n\t\tmake_tuple n = (Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t \"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t \"Clean supports tuples of arity 2 to 32.\")\n\t\t\t\t[] Nothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_class = ([\"class\"],\n\t{ syntax_title = \"class\"\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t})\n\nbs_code = ([\"code\", \"inline\", \"code inline\"],\n\t{ syntax_title = \"ABC code\"\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t})\n\nbs_generic = ([\"generic\", \"derive\", \"of\", \"{|*|}\"], \/\/ This * matches everything, which is intentional\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_instance = ([\"instance\"],\n\t{ syntax_title = \"instance\"\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t})\n\nbs_lambda = ([\"lambda\", \"\\\\*\", \"->\", \".\"],\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t})\n\nbs_layout_rule = ([\";\", \"{\", \"}\"],\n\t{ syntax_title = \"layout rule\"\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_list_expressions = ([\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"],\n\t{ syntax_title = \"list expression\"\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t})\n\nbs_macro = ([\":==\", \"macro\"],\n\t{ syntax_title = \"macro\"\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t})\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_pattern_newtype = ([\"=:\"],\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_code = [\":: ... =: ...\"]\n\t, syntax_description = \"A newtype is a type synonym at runtime but treated as a real type at compiletime.\\n\"\n\t + \"This allows the creation of instances and speeds the program up.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"TypeDef\" \":: T =: T Int\"\n\t\t[ EX \"TypeDef\" \":: T a =: T a\"\n\t\t]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t})\n\nbs_selection_array = ([\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"],\n\t{ syntax_title = \"array selection\"\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t})\nbs_selection_array_unique = ([\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"],\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t})\nbs_selection_record = ([\".\"],\n\t{ syntax_title = \"record selection\"\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t})\nbs_selection_record_unique = ([\"!\"],\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n\nbs_zf = ([\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"],\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t})\n","old_contents":"implementation module Builtins\n\nimport StdBool\nimport StdEnum\nimport StdInt\nimport StdList\nimport StdOverloaded\nimport StdString\n\nfrom Data.Func import $\nimport Data.List\nimport Data.Maybe\nimport Text\n\nimport Type\n\nimport Cloogle\nimport Doc\nimport CloogleDB\n\nbuiltin_functions :: [(Location, FunctionEntry)]\nbuiltin_functions\n\t= [ ( Builtin \"if\" [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t , {zero & fe_type=Just $ Func [Type \"Bool\" [], Var \"a\", Var \"a\"] (Var \"a\") []}\n\t )\n\t , ( Builtin \"dynamic\" [CLR 10 \"8.1\" \"_Toc311798076\"]\n\t , {zero & fe_type=Just $ Func [Var \"a\"] (Type \"Dynamic\" []) [Instance \"TC\" [Var \"a\"]]}\n\t )\n\t ]\n\nbuiltin_classes :: [(Location, ClassEntry)]\nbuiltin_classes\n\t= [ ( Builtin \"TC\" [CLR 10 \"8.1.4\" \"_Toc311798080\"]\n\t , { ce_vars=[\"v\"]\n\t , ce_context=[]\n\t , ce_documentation=Nothing\n\t , ce_members=[]\n\t , ce_instances=[]\n\t , ce_derivations=[]\n\t }\n\t )\n\t ]\n\nbuiltin_types :: [(Location, TypeDefEntry)]\nbuiltin_types\n\t= [ ( Builtin \"Bool\" [CLR 6 \"4.1\" \"_Toc311798017\"]\n\t , { deft\n\t & tde_typedef.td_name = \"Bool\"\n\t , tde_typedef.td_rhs = TDRCons False\n\t [ { defc & cons_name=\"False\" }\n\t , { defc & cons_name=\"True\" }\n\t ]\n\t }\n\t )\n\t , ( Builtin \"Int\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Int\"})\n\t , ( Builtin \"Real\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Real\"})\n\t , ( Builtin \"Char\" [CLR 6 \"4.1\" \"_Toc311798017\"], {deft & tde_typedef.td_name = \"Char\"})\n\t , ( Builtin \"String\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"String\",\n\t tde_typedef.td_rhs = TDRSynonym (Type \"_#Array\" [Type \"Char\" []]) } )\n\t , ( Builtin \"Dynamic\" [CLR 10 \"8\" \"_Toc311798077\"], {deft & tde_typedef.td_name = \"Dynamic\"})\n\t , ( Builtin \"File\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"File\"})\n\t , ( Builtin \"World\" [CLR 6 \"4.7\" \"_Toc311798037\"], {deft & tde_typedef.td_name = \"World\",\n\t tde_typedef.td_uniq = True,\n\t tde_doc = Just $ TypeDoc\n\t (Just \"An object of this type is automatically created when the program is started, if needed. It makes efficient interfacing with the outside world possible. Its value is always `65536`.\")\n\t [] Nothing})\n\t , ( Builtin \"->\" [CLR 6 \"4.6\" \"_Toc311798036\"], {deft & tde_typedef.td_name = \"(->)\",\n\t tde_typedef.td_args = [Var \"a\", Var \"b\"],\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The arrow type is used to denote functions.\\n\\nOften, function types can be written in an uncurried fashion, e.g. `a b -> c` is the same as `a -> b -> c`.\")\n\t [\"The argument type\", \"The result type\"]\n\t Nothing})\n\t , ( Builtin \"()\" [], {deft & tde_typedef.td_name=\"_Unit\",\n\t tde_doc = Just $ TypeDoc\n\t (Just \"The void \/ unit type.\")\n\t [] Nothing,\n\t tde_typedef.td_rhs = TDRCons False [{defc & cons_name=\"()\"}]})\n\t : lists\n\t ++ arrays\n\t ++ tuples\n\t ]\nwhere\n\tdeft = {tde_typedef={td_name=\"\", td_uniq=False, td_args=[], td_rhs=TDRAbstract Nothing}, tde_doc=Nothing}\n\tdefc = {cons_name=\"\", cons_args=[], cons_exi_vars=[], cons_context=[], cons_priority=Nothing}\n\n\tlists = [make_list kind spine \\\\ kind <- [[], ['#'], ['!'], ['|']], spine <- [[], ['!']] | kind <> ['|'] || spine <> ['!']]\n\twhere\n\t\tmake_list :: [Char] [Char] -> (Location, TypeDefEntry)\n\t\tmake_list k s = (Builtin higherorder [CLR 6 \"4.2\" \"_Toc311798019\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['List'] ++ s)\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"A\" + kind + spine + \" list.\\n\\n\" + description)\n\t\t\t\t[\"The type of the list elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\thigherorder = toString (['[':k] ++ s` ++ [']'])\n\t\t\t\twith s` = if (s == ['!'] && k == []) [' !'] s\n\t\t\tlista = toString (['[':k] ++ ['a':s] ++ [']'])\n\t\t\tlistints = toString (['[':k] ++ ['1,1,2,3,5':s] ++ [']'])\n\t\t\tlistany = toString (['[':k] ++ ['\\\\','w':s] ++ [']'])\n\t\t\tkind = case k of\n\t\t\t\t[] -> \" normal\"\n\t\t\t\t['#'] -> \"n unboxed\"\n\t\t\t\t['!'] -> \" head strict\"\n\t\t\t\t['|'] -> \"n overloaded\"\n\t\t\tspine = case s of\n\t\t\t\t[] -> \"\"\n\t\t\t\t['!'] -> \" spine strict\"\n\n\t\t\tdescription = \"These types of list are available:\\n\\n\" +\n\t\t\t\t\"- {{`[a]`}}, a normal list\\n\" +\n\t\t\t\t\"- {{`[#a]`}}, an unboxed head-strict list (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- {{`[!a]`}}, a head-strict list (the first element is in root normal form)\\n\" +\n\t\t\t\t\"- {{`[a!]`}}, a spine-strict list (the last element is known)\\n\" +\n\t\t\t\t\"- {{`[#a!]`}}, an unboxed spine-strict list\\n\" +\n\t\t\t\t\"- {{`[!a!]`}}, a head-strict spine-strict list\\n\" +\n\t\t\t\t\"- {{`[|a]`}}, an overloaded list (one of the types above)\"\n\n\tarrays = [make_array kind \\\\ kind <- [[], ['!'], ['#']]]\n\twhere\n\t\tmake_array :: [Char] -> (Location, TypeDefEntry)\n\t\tmake_array k = (Builtin typec [CLR 6 \"4.4\" \"_Toc311798029\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = toString (['_':k] ++ ['Array'])\n\t\t\t, tde_typedef.td_args = [Var \"a\"]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ \"An array contains a finite number of elements of the same type. Access time is constant.\\n\\n\" + description)\n\t\t\t\t[\"The type of the array elements.\"]\n\t\t\t\tNothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString (['{':k]++['}'])\n\n\t\t\tdescription = \"These types of array are available:\\n\\n\" +\n\t\t\t\t\"- `{a}`, a normal array\\n\" +\n\t\t\t\t\"- `{#a}`, an unboxed strict array (elements are stored directly, without pointers)\\n\" +\n\t\t\t\t\"- `{!a}`, a strict array (the elements are in root normal form)\"\n\n\ttuples = [make_tuple n \\\\ n <- [2..32]]\n\twhere\n\t\tmake_tuple :: Int -> (Location, TypeDefEntry)\n\t\tmake_tuple n = (Builtin typec [CLR 6 \"4.3\" \"_Toc311798026\"],\n\t\t\t{ deft\n\t\t\t& tde_typedef.td_name = \"_Tuple\" <+ n\n\t\t\t, tde_typedef.td_args = [Var $ toString [v:repeatn (n \/ 26) '`'] \\\\ v <- cycle ['a'..'z'] & n <- [0..n-1]]\n\t\t\t, tde_doc = Just $ TypeDoc\n\t\t\t\t(Just $ article + \" \" + ary + \"ary tuple.\\n\\n\" +\n\t\t\t\t \"Tuples allow bundling a finite number of expressions of different types into one object without defining a new data type.\\n\\n\" +\n\t\t\t\t \"Clean supports tuples of arity 2 to 32.\")\n\t\t\t\t[] Nothing\n\t\t\t})\n\t\twhere\n\t\t\ttypec = toString ['(':repeatn (n-1) ',' ++ [')']]\n\t\t\tary = case n of\n\t\t\t\t2 -> \"bin\"\n\t\t\t\t3 -> \"tern\"\n\t\t\t\tn -> n <+ \"-\"\n\t\t\tarticle = case n of\n\t\t\t\t11 -> \"An\"\n\t\t\t\t18 -> \"An\"\n\t\t\t\t_ -> \"A\"\n\nbuiltin_syntax :: [([String], SyntaxEntry)]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_forall\n\t, bs_generic\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_otherwise\n\t, bs_pattern_named\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nCLR :: Int String String -> CleanLangReportLocation\nCLR f sec h =\n\t{ clr_version = v\n\t, clr_file = \"CleanRep.\" + v + \"_\" <+ f <+ \".htm\"\n\t, clr_section = sec\n\t, clr_heading = h\n\t}\nwhere v = \"2.2\"\n\nEX :: String String -> SyntaxExample \nEX t c = {example=c, cleanjs_type=t, cleanjs_start=Nothing}\nEXs :: String String String -> SyntaxExample\nEXs t s c = {example=c, cleanjs_type=t, cleanjs_start=Just s}\n\nbs_case = ([\"case\", \"of\", \"case of\"],\n\t{ syntax_title = \"case expression\"\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t})\n\nbs_class = ([\"class\"],\n\t{ syntax_title = \"class\"\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"ClassDef\")\n\t\t[ \"class zero a :: a \/\/ one member\" \/\/ TODO highlighting\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\" \/\/ TODO highlighting\n\t\t]\n\t})\n\nbs_code = ([\"code\", \"inline\", \"code inline\"],\n\t{ syntax_title = \"ABC code\"\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map (EX \"Function\") \/\/ TODO highlighting\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tpop_a 1\\n}\"\n\t\t]\n\t})\n\nbs_define_constant = ([\"=:\"],\n\t{ syntax_title = \"graph definition\"\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist =: [1..10000]\"]\n\t})\nbs_define_graph = ([\"=>\"],\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` at the top level makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"mylist => [1..10000]\"]\n\t})\n\nbs_dotdot = ([\"[\\\\e..]\", \"[\\\\e..\\e]\", \"[\\\\e,\\\\e..]\", \"[[\\\\e,\\\\e..\\\\e]\", \"dotdot\", \"dot-dot\"],\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t})\n\nbs_exists = ([\"E\", \"E.*\"],\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \"Function\" \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"] \/\/ TODO highlighting\n\t})\n\nbs_forall = ([\"A\", \"A.*\"],\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, EX \"Function\" \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, EX \"TypeDef\" \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t})\n\nbs_generic = ([\"generic\", \"derive\", \"of\", \"{|*|}\"], \/\/ This * matches everything, which is intentional\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"Function\" \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"Function\" \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"Function\" \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t})\n\nbs_import = ([\"import\", \"from\", \"qualified\", \"as\"],\n\t{ syntax_title = \"imports\"\n\t, syntax_code = [\"import [qualified] ... [as ...]\", \"from ... import ...\"]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"import ...\"\n\t\t, \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t]\n\t})\n\nbs_infix = ([\"infix\", \"infixl\", \"infixr\"],\n\t{ syntax_title = \"infix operator\"\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"Function\" \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \"TypeDef\" \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t})\n\nbs_instance = ([\"instance\"],\n\t{ syntax_title = \"instance\"\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t})\n\nbs_lambda = ([\"lambda\", \"\\\\*\", \"->\", \".\"],\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t})\n\nbs_layout_rule = ([\";\", \"{\", \"}\"],\n\t{ syntax_title = \"layout rule\"\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX \"Module\" $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t})\n\nbs_let = ([\"let\", \"in\", \"let in\"],\n\t{ syntax_title = \"let expression\"\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"Function\" \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t})\nbs_let_before = ([\"#\", \"#!\"],\n\t{ syntax_title = \"let before\"\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"Function\" \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t})\n\nbs_list_expressions = ([\"list\", \"[]\", \"[:]\", \":\", \"[\\\\e:\\\\e]\", \"['*\"],\n\t{ syntax_title = \"list expression\"\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t})\n\nbs_macro = ([\":==\", \"macro\"],\n\t{ syntax_title = \"macro\"\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t})\n\nbs_module = ([\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"],\n\t{ syntax_title = \"module heading\"\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map (EX \"Function\")\n\t\t[ \"definition module ...\"\n\t\t, \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"newtype definition (experimental)\"\n\t, syntax_code = [\":: ... =: T c\"]\n\t, syntax_description = \"Define a newtype, a newtype is a type synonym that is treated as a real type.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \"Function\" \":: T = T Int\"\n\t\t]\n\t})\n\nbs_otherwise = ([\"otherwise\"],\n\t{ syntax_title = \"otherwise\"\n\t, syntax_code = [\"otherwise\"]\n\t, syntax_description = \"The (optional) last alternative in a guard. It caches all other cases, and makes sure your program does not crash if none of the cases matches.\"\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macrorhs\" \"| otherwise = ...\"\n\t\t, EXs \"Function\" \"macro\" \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t})\n\nbs_pattern_named = ([\"=:\"],\n\t{ syntax_title = \"named pattern match\"\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples =\n\t\t[ EXs \"Function\" \"macro\" \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, EX \"Function\" \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t})\n\nbs_selection_array = ([\".[]\", \".[\\\\e]\", \".[,*]\", \".[\\\\e,*]\"],\n\t{ syntax_title = \"array selection\"\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t})\nbs_selection_array_unique = ([\"![]\", \"![\\\\e]\", \"![,*]\", \"![\\\\e,*]\"],\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t})\nbs_selection_record = ([\".\"],\n\t{ syntax_title = \"record selection\"\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t})\nbs_selection_record_unique = ([\"!\"],\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t})\n\nbs_strict = ([\"strict\", \"!\"],\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"Function\" \"acker :: !Int !Int -> Int\"]\n\t})\n\nbs_synonym = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: String :== {#Char}\"]\n\t})\nbs_synonym_abstract = ([\"synonym\", \":==\"],\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \"TypeDef\" \":: Stack a (:== [a])\"]\n\t})\n\nbs_update_array = ([\"&\", \"{*&*[\\\\e]*=*}\"],\n\t{ syntax_title = \"array update\"\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t})\nbs_update_record = ([\"&\", \"{*&*=*}\"],\n\t{ syntax_title = \"record update\"\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t})\n\nbs_where_class = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"ClassDef\" \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"] \/\/ TODO highlighting\n\t})\nbs_where_instance = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"Function\" \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t})\nbs_where_local = ([\"where\"],\n\t{ syntax_title = \"where\"\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t})\n\nbs_with = ([\"with\"],\n\t{ syntax_title = \"with\"\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"Function\" \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t})\n\nbs_zf = ([\"ZF-expression\", \"ZF\", \"zf\", \"comprehension\", \"<-\", \"<|-\", \"<-:\", \"\\\\\\\\\", \",\", \"&\", \"|\"],\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_code = [\"[... \\\\\\\\ ... <- ...]\"]\n\t, syntax_description = \"Constructs a list composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\"]\n\t, syntax_examples = map (EXs \"Function\" \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: for arrays\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t})\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"d3d7fc81e78b80cfca46e4e3c0851aa85657a268","subject":"Fix documentation of eqI_b family of ABC instructions","message":"Fix documentation of eqI_b family of ABC instructions\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/Builtin\/ABC.icl","new_file":"backend\/Builtin\/ABC.icl","new_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [arg, if (stack == 'A') A_OFFSET B_OFFSET]\n\t\t, aie_description = \"Checks equality between the first argument and the \" + {stack} + \"-stack element.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t, i_push_a_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\ti_push_a_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a_b\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET]\n\t\t, aie_description = \"Pushes the A-stack element as an integer (i.e., a pointer to the heap) on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t, i_push_r_arg_t\n\t, i_push_t_r_a\n\t, i_push_t_r_args\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html.\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \" - `sep` can be either `-` or `:`.\"\n\t\t\t, \" - `flags` can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \" - `input` is a number of input argument types (allowed: `IpRrSsAOF`; see below).\"\n\t\t\t, \" - `output` is a number of output argument types (allowed: `VIpRrSsAOF`; see below).\"\n\t\t\t, \" - `state` is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \" - `I` for integers\"\n\t\t\t, \" - `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \" - [`Rr`] for reals\"\n\t\t\t, \" - `S` for Clean Strings (`{#Char}`). If used as input type this passes a pointer to the string's length (number of characters). The actual array is at offset 4\/8 (32\/64 bit). If this is used as output type, the C function has to return a pointer to the string's length, followed by the actual string. A copy of the string will be created in the Clean heap, and this copy will be used by Clean. If the string was allocated in C, for example using malloc, it should be deallocated in C when it is no longer used.\"\n\t\t\t, \" - `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}}, as the string is not null-terminated). The length (number of characters) is at offset -4\/-8. (32\/64 bit).\"\n\t\t\t, \" - `A` for A-stack elements. A pointer to the third block of the node is passed. For arrays, this is a pointer to the elements. One word higher is the element type. The size of the array is two words higher.\"\n\t\t\t, \" - [`OF`] for function pointers\"\n\t\t\t, \" - `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\n\ti_push_r_arg_t =\n\t\t{ zero\n\t\t& aie_instruction = \"push_r_arg_t\"\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Gets the *n*th element from the type string of a record.\"\n\t\t\t, \"The type string is on top of the B-stack; *n* below that.\"\n\t\t\t]\n\t\t}\n\ti_push_t_r_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Push the address of the type string of the referenced record to the B-stack.\"\n\t\t}\n\ti_push_t_r_args =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_args\"\n\t\t, aie_description = \"Pops a record from the A-stack, pushes its members in reversed order to both of the stacks, then pushes the address of the type string to the B-stack.\"\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_n\n\t, d_nu\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_n =\n\t\t{ zero\n\t\t& aie_instruction = \".n\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t, \"\\n\\nThere are some special cases:\\n\\n\"\n\t\t\t, \"- An arity of `-1` is for tuple selectors;\\n\"\n\t\t\t, \"- An arity of `-2` is for indirection nodes;\\n\"\n\t\t\t, \"- An arity of `-3` is for record selectors of basic types;\\n\"\n\t\t\t, \"- An arity of `-4` is for record selectors of non-basic types.\\n\\n\"\n\t\t\t, \"See also {{`.nu`}}.\"\n\t\t\t]\n\t\t}\n\td_nu =\n\t\t{ zero\n\t\t& aie_instruction = \".nu\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels with arguments on the B-stack (otherwise, {{`.n`}} is used).\"\n\t\t\t, \"The first integer is the number of A-stack arguments; the second the number of B-stack arguments.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","old_contents":"implementation module Builtin.ABC\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle.API\nimport Cloogle.DB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_create\n\t: arith_instructions ++\n\t stack_operations ++\n\t branches ++\n\t miscellaneous ++\n\t directives ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nA_OFFSET :== ABCArgument ABCTypeAStackOffset False\nB_OFFSET :== ABCArgument ABCTypeBStackOffset False\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_create :: ABCInstructionEntry\ni_create =\n\t{ zero\n\t& aie_instruction = \"create\"\n\t, aie_description = \"Creates a new empty node and pushes its address to the A-stack.\"\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, i_eqAC_a\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, eq_arg \"Bool\" BOOL 'A'\n\t, eq_arg \"Bool\" BOOL 'B'\n\t, eq_arg \"Char\" CHAR 'A'\n\t, eq_arg \"Char\" CHAR 'B'\n\t, eq_arg \"Int\" INT 'A'\n\t, eq_arg \"Int\" INT 'B'\n\t, eq_arg \"Real\" REAL 'A'\n\t, eq_arg \"Real\" REAL 'B'\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\teq_arg :: !String !ABCArgument !Char -> ABCInstructionEntry\n\teq_arg type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = {'e','q',type.[0],'_',toLower stack}\n\t\t, aie_arguments = [if (stack == 'A') A_OFFSET B_OFFSET, arg]\n\t\t, aie_description = \"Checks equality between the \" + {stack} + \"-stack element and the second argument.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\n\ti_eqAC_a =\n\t\t{ zero\n\t\t& aie_instruction = \"eqAC_a\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Checks that the string on top of the A-stack equals the argument string.\"\n\t\t}\n\nstack_operations :: [ABCInstructionEntry]\nstack_operations =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, i_buildAC\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t, i_create_array\n\t, i_create_array_\n\t, i_eq_desc\n\t, i_eq_desc_b\n\t, i_eq_nulldesc\n\t, i_pop_a\n\t, i_pop_b\n\t, i_push_a\n\t, i_push_b\n\t, i_push_a_b\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\ti_buildAC =\n\t\t{ zero\n\t\t& aie_instruction = \"buildAC\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Pushes the argument string to the A-stack.\"\n\t\t}\n\n\ti_create_array =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size and initial value are popped from the B and A stacks.\"\n\t\t\t]\n\t\t}\n\ti_create_array_ =\n\t\t{ zero\n\t\t& aie_instruction = \"create_array_\"\n\t\t, aie_arguments = [LABEL, A_OFFSET, B_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Creates an array on the A-stack.\"\n\t\t\t, \"The elements have type `label` (which can be `_` for any A-stack type).\"\n\t\t\t, \"The last two arguments indicate the stack sizes of the elements.\"\n\t\t\t, \"The size is popped from the B-stack; the elements are initialised as `_Nil` regardless of the type.\"\n\t\t\t]\n\t\t}\n\n\ti_eq_desc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc\"\n\t\t, aie_arguments = [LABEL, INT, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Checks that the indicated node on the A-stack matches the descriptor given by the label.\"\n\t\t\t, \"The `int` argument is the arity of the descriptor.\"\n\t\t\t]\n\t\t}\n\ti_eq_desc_b =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_desc_b\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = join \" \"\n\t\t\t[ \"The indicated node on the A-stack is assumed to be an array.\"\n\t\t\t, \"The instruction checks that the array is of the type indicated by `label`.\"\n\t\t\t]\n\t\t}\n\ti_eq_nulldesc =\n\t\t{ zero\n\t\t& aie_instruction = \"eq_nulldesc\"\n\t\t, aie_arguments = [LABEL, A_OFFSET]\n\t\t, aie_description = \"Checks that the indicated node on the A-stack matches the descriptor given by the label, ignoring arity.\"\n\t\t}\n\n\ti_pop_a =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pops elements off the A-stack until the referenced element.\"\n\t\t}\n\ti_pop_b =\n\t\t{ zero\n\t\t& aie_instruction = \"pop_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pops elements off the B-stack until the referenced element.\"\n\t\t}\n\ti_push_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the referenced A-stack element on the A-stack.\"\n\t\t}\n\ti_push_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_b\"\n\t\t, aie_arguments = [B_OFFSET]\n\t\t, aie_description = \"Pushes the referenced B-stack element on the B-stack.\"\n\t\t}\n\ti_push_a_b =\n\t\t{ zero\n\t\t& aie_instruction = \"push_a_b\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET]\n\t\t, aie_description = \"Pushes the A-stack element as an integer (i.e., a pointer to the heap) on the B-stack.\"\n\t\t}\n\nbranches :: [ABCInstructionEntry]\nbranches =\n\t[ i_jmp\n\t, i_jmp_false\n\t, i_jmp_true\n\t, i_jsr\n\t, i_jsr_eval\n\t, i_rtn\n\t]\nwhere\n\ti_jmp =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Unconditional jump to a label.\"\n\t\t}\n\ti_jmp_false =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_false\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is false.\"\n\t\t}\n\ti_jmp_true =\n\t\t{ zero\n\t\t& aie_instruction = \"jmp_true\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Jump to a label if the Bool on top of the B-stack is true.\"\n\t\t}\n\ti_jsr =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Subroutine jump to a label. {{`rtn`}} returns to the instruction after this `jsr`.\"\n\t\t}\n\ti_jsr_eval =\n\t\t{ zero\n\t\t& aie_instruction = \"jsr_eval\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = \"Subroutine jump to evaluate the indicated A-stack element. {{`rtn`}} returns to the instruction after this `jsr_eval`.\"\n\t\t}\n\ti_rtn =\n\t\t{ zero\n\t\t& aie_instruction = \"rtn\"\n\t\t, aie_description = \"Returns from a subroutine call (e.g. {{`jsr`}}).\"\n\t\t}\n\nmiscellaneous :: [ABCInstructionEntry]\nmiscellaneous =\n\t[ i_ccall\n\t, i_centry\n\t, i_get_node_arity\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t, i_push_r_arg_t\n\t, i_push_t_r_a\n\t, i_push_t_r_args\n\t]\nwhere\n\ti_ccall =\n\t\t{ zero\n\t\t& aie_instruction = \"ccall\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Calls a C function.\"\n\t\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html.\"\n\t\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t\t, \"\\n\"\n\t\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t\t, \" - `sep` can be either `-` or `:`.\"\n\t\t\t, \" - `flags` can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t\t, \" - `input` is a number of input argument types (allowed: `IpRrSsAOF`; see below).\"\n\t\t\t, \" - `output` is a number of output argument types (allowed: `VIpRrSsAOF`; see below).\"\n\t\t\t, \" - `state` is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t\t, \"\\n\"\n\t\t\t, \"Input, output and state argument types can be:\"\n\t\t\t, \" - `I` for integers\"\n\t\t\t, \" - `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t\t, \" - [`Rr`] for reals\"\n\t\t\t, \" - `S` for Clean Strings (`{#Char}`). If used as input type this passes a pointer to the string's length (number of characters). The actual array is at offset 4\/8 (32\/64 bit). If this is used as output type, the C function has to return a pointer to the string's length, followed by the actual string. A copy of the string will be created in the Clean heap, and this copy will be used by Clean. If the string was allocated in C, for example using malloc, it should be deallocated in C when it is no longer used.\"\n\t\t\t, \" - `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}}, as the string is not null-terminated). The length (number of characters) is at offset -4\/-8. (32\/64 bit).\"\n\t\t\t, \" - `A` for A-stack elements. A pointer to the third block of the node is passed. For arrays, this is a pointer to the elements. One word higher is the element type. The size of the array is two words higher.\"\n\t\t\t, \" - [`OF`] for function pointers\"\n\t\t\t, \" - `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t\t]\n\t\t}\n\ti_centry =\n\t\t{ zero\n\t\t& aie_instruction = \"centry\"\n\t\t, aie_arguments = [LABEL, LABEL, STRING]\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t\t, \"The first label is the name of the C function to generate.\"\n\t\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t\t, \"The string argument indicates the type.\"\n\t\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_get_node_arity =\n\t\t{ zero\n\t\t& aie_instruction = \"get_node_arity\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Pushes the arity of the descriptor of the referenced A-stack element to the B-stack.\"\n\t\t}\n\n\ti_halt =\n\t\t{ zero\n\t\t& aie_instruction = \"halt\"\n\t\t, aie_description = \"Terminates the program immediately.\"\n\t\t}\n\n\ti_instruction =\n\t\t{ zero\n\t\t& aie_instruction = \"instruction\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t\t}\n\n\ti_load_i =\n\t\t{ zero\n\t\t& aie_instruction = \"load_i\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si16 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si16\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_si32 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_si32\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t\t]\n\t\t}\n\ti_load_ui8 =\n\t\t{ zero\n\t\t& aie_instruction = \"load_ui8\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = join \"\\n\\n\"\n\t\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t\t]\n\t\t}\n\n\ti_no_op =\n\t\t{ zero\n\t\t& aie_instruction = \"no_op\"\n\t\t, aie_description = join \"\\n\"\n\t\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t\t, \"```clean\"\n\t\t\t, \"cast :: .a -> .b\"\n\t\t\t, \"cast _ = code {\"\n\t\t\t, \"\\tno_op\"\n\t\t\t, \"}\"\n\t\t\t, \"```\"\n\t\t\t]\n\t\t}\n\n\ti_push_r_arg_t =\n\t\t{ zero\n\t\t& aie_instruction = \"push_r_arg_t\"\n\t\t, aie_description = join \" \"\n\t\t\t[ \"Gets the *n*th element from the type string of a record.\"\n\t\t\t, \"The type string is on top of the B-stack; *n* below that.\"\n\t\t\t]\n\t\t}\n\ti_push_t_r_a =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_a\"\n\t\t, aie_arguments = [A_OFFSET]\n\t\t, aie_description = \"Push the address of the type string of the referenced record to the B-stack.\"\n\t\t}\n\ti_push_t_r_args =\n\t\t{ zero\n\t\t& aie_instruction = \"push_t_r_args\"\n\t\t, aie_description = \"Pops a record from the A-stack, pushes its members in reversed order to both of the stacks, then pushes the address of the type string to the B-stack.\"\n\t\t}\n\ndirectives :: [ABCInstructionEntry]\ndirectives =\n\t[ d_d\n\t, d_n\n\t, d_nu\n\t, d_o\n\t, d_export\n\t, d_inline\n\t, d_module\n\t, d_depend\n\t, d_end\n\t, d_endinfo\n\t, d_start\n\t]\nwhere\n\td_d =\n\t\t{ zero\n\t\t& aie_instruction = \".d\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\td_n =\n\t\t{ zero\n\t\t& aie_instruction = \".n\"\n\t\t, aie_arguments = [A_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t, \"\\n\\nThere are some special cases:\\n\\n\"\n\t\t\t, \"- An arity of `-1` is for tuple selectors;\\n\"\n\t\t\t, \"- An arity of `-2` is for indirection nodes;\\n\"\n\t\t\t, \"- An arity of `-3` is for record selectors of basic types;\\n\"\n\t\t\t, \"- An arity of `-4` is for record selectors of non-basic types.\\n\\n\"\n\t\t\t, \"See also {{`.nu`}}.\"\n\t\t\t]\n\t\t}\n\td_nu =\n\t\t{ zero\n\t\t& aie_instruction = \".nu\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, LABEL]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates the arity of node entry labels with arguments on the B-stack (otherwise, {{`.n`}} is used).\"\n\t\t\t, \"The first integer is the number of A-stack arguments; the second the number of B-stack arguments.\"\n\t\t\t, \"The label is the label of the corresponding descriptor, or `_` if it does not exist.\"\n\t\t\t]\n\t\t}\n\td_o =\n\t\t{ zero\n\t\t& aie_instruction = \".o\"\n\t\t, aie_arguments = [A_OFFSET, B_OFFSET, STRING_]\n\t\t, aie_description = concat\n\t\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t\t]\n\t\t}\n\n\td_export =\n\t\t{ zero\n\t\t& aie_instruction = \".export\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Exports a label (allows linking).\"\n\t\t}\n\td_inline =\n\t\t{ zero\n\t\t& aie_instruction = \".inline\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates that a label can (should) be inlined (usually for performance reasons).\"\n\t\t}\n\n\td_module =\n\t\t{ zero\n\t\t& aie_instruction = \".module\"\n\t\t, aie_arguments = [LABEL, STRING]\n\t\t, aie_description = \"Indicates the name of the module, and its label in the data segment.\"\n\t\t}\n\td_depend =\n\t\t{ zero\n\t\t& aie_instruction = \".depend\"\n\t\t, aie_arguments = [STRING]\n\t\t, aie_description = \"Indicates a module that this module depends on.\"\n\t\t}\n\td_end =\n\t\t{ zero\n\t\t& aie_instruction = \".end\"\n\t\t, aie_description = \"Indicates the end of the ABC file.\"\n\t\t}\n\td_endinfo =\n\t\t{ zero\n\t\t& aie_instruction = \".endinfo\"\n\t\t, aie_description = \"Indicates the end of the metadata in the ABC file.\"\n\t\t}\n\td_start =\n\t\t{ zero\n\t\t& aie_instruction = \".start\"\n\t\t, aie_arguments = [LABEL]\n\t\t, aie_description = \"Indicates the label to start execution at.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqD_b\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_not_eqZ\"\n\t, \"jrsr\"\n\t, \"jsr_ap\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".keep\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".string\"\n\t]\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"cf9093268fb581add17fdaeee7810febcbd942b7","subject":"Copy edited #195","message":"Copy edited #195\n","repos":"clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle,clean-cloogle\/cloogle.org","old_file":"backend\/Builtin\/Syntax.icl","new_file":"backend\/Builtin\/Syntax.icl","new_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\\n\"\n\t\t, \"The context of a generic function can only contain other generic functions.\"\n\t\t, \"The generic context is written without kinds and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int \/\/ generic context\"\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","old_contents":"implementation module Builtin.Syntax\n\nimport StdArray\nimport StdList\nimport StdString\n\nimport Data.Error\nfrom Data.Func import $\nimport Data.Maybe\nimport Text\n\nimport Regex\nexact s = regex (\"^\" +++ s +++ \"$\")\n\nimport Cloogle.API\nimport Cloogle.DB\n\nimport Builtin.Predef\n\nbuiltin_syntax :: [SyntaxEntry]\nbuiltin_syntax =\n\t[ bs_case\n\t, bs_class\n\t, bs_code\n\t, bs_comments\n\t, bs_context\n\t, bs_define_constant\n\t, bs_define_graph\n\t, bs_dotdot\n\t, bs_exists\n\t, bs_extensible_adt\n\t, bs_forall\n\t, bs_foreign\n\t, bs_funcdep\n\t, bs_function_definition\n\t, bs_guard\n\t, bs_generic\n\t, bs_hierarchical_modules\n\t, bs_import\n\t, bs_infix\n\t, bs_instance\n\t, bs_lambda\n\t, bs_layout_rule\n\t, bs_let\n\t, bs_let_before\n\t, bs_list_expressions\n\t, bs_macro\n\t, bs_module\n\t, bs_newtype\n\t, bs_overloaded_type_variable\n\t, bs_pattern_named\n\t, bs_pattern_predicate\n\t, bs_qualified_identifier\n\t, bs_record_disambiguation\n\t, bs_selection_array\n\t, bs_selection_array_unique\n\t, bs_selection_record\n\t, bs_selection_record_unique\n\t, bs_strict\n\t, bs_synonym\n\t, bs_synonym_abstract\n\t, bs_type_definition\n\t, bs_type_specification\n\t, bs_unique\n\t, bs_update_array\n\t, bs_update_record\n\t, bs_where_class\n\t, bs_where_instance\n\t, bs_where_local\n\t, bs_with\n\t, bs_zf\n\t]\n\nEX :: !String -> SyntaxExample \nEX c = {example=c, cleanjs_start=Nothing}\nEXs :: !String !String -> SyntaxExample\nEXs s c = {example=c, cleanjs_start=Just s}\n\nbs_case =\n\t{ syntax_title = \"case expression\"\n\t, syntax_patterns = map exact [\"case\", \"of\", \"case of\", \"->\", \"=\"]\n\t, syntax_code = [\"case ... of ...\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Pattern match on an expression and do something depending on the alternative of the matching pattern.\"\n\t\t, \"Both `->` and `=` can be used to separate patterns and alternatives, however, they cannot be mixed.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.4.2\" \"_Toc311798001\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"isJust m = case m of\\n\\tJust _ -> True\\n\\t_ -> False\"\n\t\t]\n\t}\n\nbs_class =\n\t{ syntax_title = \"class\"\n\t, syntax_patterns = map exact [\"class\"]\n\t, syntax_code =\n\t\t[ \"class ... ... :: ...\"\n\t\t, \"class ... ... where ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Classes are (sets of) overloaded functions. For classes with only one member function, a simplified syntax exists.\\n\\n\" +\n\t\t\"Types can instantiate classes with the {{`instance`}} keyword.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"class zero a :: a \/\/ one member\"\n\t\t, \"class Text s \/\/ multiple members\\nwhere\\n\\ttextSize :: !s -> Int\\n\\tconcat :: ![s] -> s\\n\\t\/\/ ...\"\n\t\t]\n\t}\n\nbs_code =\n\t{ syntax_title = \"ABC code\"\n\t, syntax_patterns = map exact [\"code\", \"inline\", \"code inline\"]\n\t, syntax_code = [\"... = code [inline] { ... }\"]\n\t, syntax_description =\n\t\t\"A code block with raw ABC instructions, which can be used for primitive functions like integer addition, for linking with C, bypassing the type system... welcome down the rabbit hole!\\n\\n\" +\n\t\t\"When `inline` is used, the function will be inlined when applied in a strict context.\"\n\t, syntax_doc_locations = [CLR 13 \"11.2\" \"_Toc311798115\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: !Int !Int -> Int \/\/ Primitive function\\nadd a b = code inline {\\n\\taddI\\n}\"\n\t\t, \"sleep :: !Int !*World -> *(!Int, !*World) \/\/ Linking with C\\nsleep n w = code {\\n\\tccall sleep \\\"I:I:A\\\"\\n}\"\n\t\t, \"cast :: !.a -> .b \/\/ Bypassing the type system\\ncast _ = code {\\n\\tno_op\\n}\"\n\t\t]\n\t}\n\nbs_comments =\n\t{ syntax_title = \"comments\"\n\t, syntax_patterns = map exact [\"\/\/\", \"\/\\\\*.*\\\\*\/\"]\n\t, syntax_code = [\"\/\/ ...\", \"\/* ... *\/\"]\n\t, syntax_description = \"`\/\/` adds a single-line comment. `\/*` and `*\/` encapsulate a multi-line comment. Multi-line comments can be nested.\"\n\t, syntax_doc_locations = [CLR 15 \"B.2\" \"_Toc311798132\"]\n\t, syntax_examples = []\n\t}\n\nbs_context =\n\t{ syntax_title = \"type context\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"&\", \",\", \"special\"]\n\t, syntax_code = [\":: ... | ..., ... [special ...=...]\", \"| ... & ..., ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"A type context indicates what {{class}}es must be instantiated by type variables.\\n\"\n\t\t, \"For function types, the type context starts with `|`.\"\n\t\t, \"Several classes can be given to the same variable with `,`.\"\n\t\t, \"To add multiple restrictions, use `&`.\\n\"\n\t\t, \"In constructors, the type context starts with `&`.\\n\"\n\t\t, \"Uniqueness constraints can be given with `,`. For details, see under {{`,`}}.\\n\"\n\t\t, \"With the `special` keyword, specialised instances for certain type instantiations are exported for efficiency.\"\n\t\t, \"A generic function can only contain a generic context written with a different syntax.\"\n\t\t, \"The generic dependency is written without the kind specification and separated by `,` as seen in the example.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 8 \"6.2\" \"_Toc311798057\"]\n\t, syntax_examples = map EX\n\t\t[ \"add :: a a -> a | + a \/\/ a must instantiate +\\nadd x y = x + y\"\n\t\t, \"sum :: [a] -> a | zero, + a \/\/ a must instantiate zero and +\\nsum [] = zero\\nsum [x:xs] = x + sum xs\"\n\t\t, \"(<+) infixr 5 :: a b -> String | toString a & toString b \/\/ a and b must instantiate toString\\n(<+) x y = toString x +++ toString y\"\n\t\t, \"isMember :: a [a] -> Bool special a=Int \/\/ specialised instance for integer lists for efficiency\"\n\t\t, \"generic gFun a | gDefault a, gEq a :: a -> Int\" \/\/ Generic dependency\n\t\t]\n\t}\n\nbs_define_constant =\n\t{ syntax_title = \"graph definition\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"... =: ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=:` at the top level makes sure they are shared through out the program; hence, they are evaluated only once.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in local scope.\\n\\n\" +\n\t\t\"The inverse is {{`=>`}}, which defines an identifier to be a constant function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist =: [1..10000]\"]\n\t}\nbs_define_graph =\n\t{ syntax_title = \"constant function definition\"\n\t, syntax_patterns = map exact [\"=>\"]\n\t, syntax_code = [\"... => ...\"]\n\t, syntax_description =\n\t\t\"Defining constants with `=>` makes sure they are interpreted as constant functions; hence, they are evaluated every time they are needed.\\n\\n\" +\n\t\t\"This is the default understanding of `=` in global scope.\\n\\n\" +\n\t\t\"The inverse is {{`=:`}}, which defines an identifier to be a graph.\"\n\t, syntax_doc_locations = [CLR 5 \"3.6\" \"_Toc311798007\"]\n\t, syntax_examples = [EXs \"macro\" \"mylist => [1..10000]\"]\n\t}\n\nbs_dotdot =\n\t{ syntax_title = \"dotdot expression\"\n\t, syntax_patterns = map exact [\"\\\\[\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w\\\\.\\\\.\\\\w\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\]\", \"\\\\[\\\\w,\\\\w\\\\.\\\\.\\\\w\\\\]\", \"dotdot\", \"dot-dot\", \"\\\\.\\\\.\"]\n\t, syntax_code = [\"[i..]\", \"[i..k]\", \"[i,j..]\", \"[i,j..k]\"]\n\t, syntax_description =\n\t\t\"A shorthand for lists of enumerable types.\\n\\n\" +\n\t\t\"To use these expressions, you must import {{`StdEnum`}}. The underlying functions are defined in {{`_SystemEnum`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798023\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"xs = [0..] \/\/ 0, 1, 2, 3, ...\"\n\t\t, \"xs = [0,2..] \/\/ 0, 2, 4, 6, ...\"\n\t\t, \"xs = [0..10] \/\/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10\"\n\t\t, \"xs = [0,2..10] \/\/ 0, 2, 4, 6, 8, 10\"\n\t\t]\n\t}\n\nbs_exists =\n\t{ syntax_title = \"existential quantifier\"\n\t, syntax_patterns = map exact [\"E\", \"E\\\\.*\"]\n\t, syntax_code = [\":: ... = E. ...: ...\"]\n\t, syntax_description = \"Existential quantifiers make it possible to define (recursive) objects of the same type with different types of content.\"\n\t, syntax_doc_locations = [CLR 7 \"5.1.3\" \"_Toc311798042\"]\n\t, syntax_examples = [EX \":: List = E.e: Cons e List | Nil\\nStart = Cons 5 (Cons 'a' (Cons \\\"abc\\\" Nil))\"]\n\t}\n\nbs_extensible_adt =\n\t{ syntax_title = \"extensible algebraic data type\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\.\", \"\\\\|\"]\n\t, syntax_code = [\":: T | ...\", \":: T = ... | ... | ..\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Extensible algebraic data types are ADTs that can be extended in other modules.\"\n\t\t, \"One module can declare the ADT as extendible by adding the `..` constructor.\"\n\t\t, \"Other modules can then extend it.\"\n\t\t, \"However, extensions can not be exported.\"\n\t\t, \"It is also not possible to derive generic functions for EADTs.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: T = .. \/\/ Declare T as an EADT\"\n\t\t, \":: T = C1 | .. \/\/ Declare T to be an EADT with at least the constructor C1\"\n\t\t, \":: T | C \/\/ Extend the EADT T with constructor C\"\n\t\t]\n\t}\n\nbs_forall =\n\t{ syntax_title = \"universal quantifier\"\n\t, syntax_patterns = map exact [\"A\", \"A\\\\.*\"]\n\t, syntax_code = [\"A. ...:\"]\n\t, syntax_description = \"Explicitly marks polymorphic type variables. Clean does not yet allow universal quantifiers on the topmost level.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.4\" \"_Toc311798013\"]\n\t, syntax_examples = map EX\n\t\t[ \"hd :: A.a: [a] -> a \/\/ Not yet allowed: A. on the topmost level\"\n\t\t, \"h :: (A.a: [a] -> Int) -> Int \/\/ The quantifier is needed to apply the function to both a [Int] and a [Char]\\nh f = f [1..100] + f ['a'..'z']\"\n\t\t, \":: T = C (A.a: a -> a) \/\/ In a type\"\n\t\t]\n\t}\n\nbs_foreign =\n\t{ syntax_title = \"foreign export\"\n\t, syntax_patterns = map exact [\"foreign\", \"export\", \"ccall\", \"stdcall\"]\n\t, syntax_code =\n\t\t[ \"foreign export [ccall | stdcall] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Exports the Clean function symbol to the binary.\\n\\n\" +\n\t\t\"This is only possible if the function is also in the definition module and all arguments are basic types or tuples and fully strict.\"\n\t, syntax_doc_locations = [CLR 13 \"11.1\" \"_Toc311798114\"]\n\t, syntax_examples = map EX\n\t\t[ \"foreign export factorial \/\/ Export the factorial function\"\n\t\t, \"foreign export stdcall factorial \/\/ Idem but with the stdcall calling convention\"\n\t\t]\n\t}\n\nbs_funcdep =\n\t{ syntax_title = \"functional dependency\"\n\t, syntax_patterns = map exact [\"~\"]\n\t, syntax_code =\n\t\t[ \"class ... ~... ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Lets you point the type checker to the type that determines the other types.\\n\\n\" +\n\t\t\"Most often this is the return type (undocumented and experimental).\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"class plus a b c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Results in: internal overloading of \\\"plus\\\" could not be solved because the compiler doesn't know the type of the intermediate result.\"\n\t\t, \"class plus a b ~c :: a b -> c\\n\" +\n\t\t \"instance plus Int Int Int where plus x y = x + y\\n\" +\n\t\t \"Start = plus 1 (plus 1 1) \/\/ Works! because we told the compiler that c determines the other types.\"\n\t\t]\n\t}\n\nbs_function_definition =\n\t{ syntax_title = \"function definition\"\n\t, syntax_patterns = map exact [\"=\"]\n\t, syntax_code = [\"... = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Specifies the implementation of a function\\n.\"\n\t\t, \"Instead of `=`, also {{`=:`}} and {{`=>`}} may be used to separate the pattern from the right-hand side.\"\n\t\t, \"These have different semantics.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3\" \"_Toc311797995\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b]\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_guard =\n\t{ syntax_title = \"guard\"\n\t, syntax_patterns = map exact [\"\\\\|\", \"=\", \"otherwise\"]\n\t, syntax_code = [\"| ... = ...\", \"| otherwise = ...\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Guards let you specify function alternatives with boolean expressions.\"\n\t\t, \"A final `otherwise` guard can be used to ensure the function is total.\\n\"\n\t\t, \"Guards can be nested with indentation.\"\n\t\t, \"However, only the toplevel guards may be partial.\\n\"\n\t\t, \"To separate the guard from the alternative, both {{`=`}} and {{`=>`}} may be used (with different semantics; see {{`=>`}}).\"\n\t\t, \"However, one must be consistent with this throughout the function.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 5 \"3.3\" \"_Toc311797998\"]\n\t, syntax_examples = map EX\n\t\t[ \"sign :: !Int -> Int\\nsign n\\n| n < 0 = -1 \/\/ Negative number\\n| n == 0 = 0 \/\/ Zero\\n| otherwise = 1 \/\/ Must be positive\"\n\t\t]\n\t}\n\nbs_generic =\n\t{ syntax_title = \"generic function definition\"\n\t, syntax_patterns = map exact [\"generic\", \"derive\", \"of\", \"\\\\{\\\\|.*\\\\|\\\\}\"]\n\t, syntax_code = [\"generic ... ... :: ...\", \"derive ... ...\"]\n\t, syntax_description = \"With generics, a function can be defined once and derived for (almost) all possible types, to avoid very similar code snippets.\"\n\t, syntax_doc_locations = [CLR 9 \"7.2\" \"_Toc311798069\"]\n\t, syntax_examples =\n\t\t[ EX \"generic gEq a :: !a !a -> Bool \/\/ The type of a generic function\"\n\t\t, EXs \"macro\" $ \"gEq{|Int|} x y = x == y \/\/ Implementation of a generic\\n\" +\n\t\t \"gEq{|PAIR|} fx fy (PAIR x1 y1) (PAIR x2 y2) = fx x1 x2 && fy y1 y2\" \/\/ TODO highlighting\n\t\t, EX \"derive gEq [] \/\/ Deriving the gEq generic for type []\"\n\t\t, EXs \"macro\" \"gConsName{|CONS of d|} _ = d.gcd_name \/\/ Using type information\"\n\t\t]\n\t}\n\nbs_hierarchical_modules =\n\t{ syntax_title = \"hierarchical module names\"\n\t, syntax_patterns = [exact \"\\\\.\"]\n\t, syntax_code = [\"... . ...\"]\n\t, syntax_description = \"Modules can be structured hierarchically. For instance, module `Control.Monad` can be found in `Control\/Monad.[di]cl`.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"definition module Control.Monad\"]\n\t}\n\nbs_import =\n\t{ syntax_title = \"imports\"\n\t, syntax_patterns = map exact [\"import\", \"from\", \"qualified\", \"as\", \"=>\", \"code\", \"library\"]\n\t, syntax_code =\n\t\t[ \"import [qualified] ... [as ...]\"\n\t\t, \"from ... import ...\"\n\t\t, \"import ... => qualified ...\"\n\t\t, \"import code from [library] ...\"\n\t\t]\n\t, syntax_description =\n\t\t\"Imports code from other modules.\\n\\n\" +\n\t\t\"With the `from` keyword, one can achieve more granularity.\\n\\n\" +\n\t\t\"In case of name clashes, `qualified` can be used (undocumented).\\n\\n\" +\n\t\t\"Moreover, you can import from object files or windows DLLs.\"\n\t, syntax_doc_locations = [CLR 4 \"2.5\" \"_Toc311797991\"]\n\t, syntax_examples = map EX\n\t\t[ \"import StdEnv \/\/ Import all code from the StdEnv definition module\"\n\t\t, \"from StdFunc import o \/\/ Import only the o function from StdFunc\"\n\t\t, \"import qualified Data.Map \/\/ Import Data.Map such that functions are available as e.g. 'Data.Map'.get.\"\n\t\t, \"import qualified Data.Map as M \/\/ Import Data.Map such that functions are available as e.g. 'M'.get.\"\n\t\t, \"import Control.Monad => qualified join \/\/ Import all code from Control.Monad except for join. join is imported qualified\"\n\t\t, \"import code from \\\"tty.\\\" \/\/ Import functions from the object file matching 'Clean System Files\/tty.*'\"\n\t\t, \"import code from library \\\"msvcrt\\\" \/\/ Import functions from linked DLLs according to the msvcrt file in Clean System Files.\\n\" +\n\t\t \" \/\/ The file should start with the DLL name (e.g. msvcrt) and followed by one line per function you want to link.\"\n\t\t]\n\t}\n\nbs_infix =\n\t{ syntax_title = \"infix operator\"\n\t, syntax_patterns = map exact [\"infix\", \"infixl\", \"infixr\"]\n\t, syntax_code = [\"infix[l,r] [...]\"]\n\t, syntax_description =\n\t\t\"Defines a function with arity 2 that can be used in infix position.\\n\\n\" +\n\t\t\"The following number, if any, determines the precedence.\\n\\n\" +\n\t\t\"`infixl` and `infixr` indicate associativity.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.2\" \"_Toc311798011\"]\n\t, syntax_examples =\n\t\t[ EX \"(bitor) infixl 6 :: !Int !Int -> Int \/\/ Left-associative infix function with precedence 6\"\n\t\t, EXs \"macro\" \"(o) infixr 9 \/\/ Infix macro\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t, EX \":: MyType = (:+:) infixl 6 Int Int \/\/ Infix data constructor, can be used as (5 :+: 10)\"\n\t\t]\n\t}\n\nbs_instance =\n\t{ syntax_title = \"instance\"\n\t, syntax_patterns = map exact [\"instance\"]\n\t, syntax_code = [\"instance ... ... where ...\"]\n\t, syntax_description = \"Defines an instantiation of a {{class}} for a type.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = map EX\n\t\t[ \"instance zero Int\\nwhere\\n\\tzero = 0\"\n\t\t, \"instance zero Real\\nwhere\\n\\tzero = 0.0\"\n\t\t]\n\t}\n\nbs_lambda =\n\t{ syntax_title = \"lambda abstraction\"\n\t, syntax_patterns = map exact [\"lambda\", \"=\", \"->\", \"\\\\.\"]\n\t, syntax_code = [\"\\\\... -> ...\", \"\\\\... . ...\", \"\\\\... = ...\"]\n\t, syntax_description = \"An anonymous, inline function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.4.1\" \"_Toc311798000\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(o) f g = \\\\x -> f (g x) \/\/ Simple lambda expression\"\n\t\t, \"swapall = map (\\\\(x,y) -> (y,x)) \/\/ Pattern matching in lambda arguments\"\n\t\t, \"mul = \\\\x y -> x * y \/\/ Multiple arguments (of course, it would be better to write `mul x y = x * y` or `mul = (*)`)\"\n\t\t]\n\t}\n\nbs_layout_rule =\n\t{ syntax_title = \"layout rule\"\n\t, syntax_patterns = map exact [\";\", \"\\\\{\", \"\\\\}\"]\n\t, syntax_code = [\"...;\", \"{ ... }\"]\n\t, syntax_description =\n\t\t\"Most Clean programs are written using the layout rule, which means that scopes are indicated with indent levels.\" +\n\t\t\"The layout sensitive mode can be turned off by adding a semicolon `;` at the end of the {{module}} line.\" +\n\t\t\"Then, scopes have to be indicated with `{ ... }` and definitions have to end with `;`.\"\n\t, syntax_doc_locations = [CLR 4 \"2.3.3\" \"_Toc311797989\"]\n\t, syntax_examples = [EX $\n\t\t\"module test;\\n\" +\n\t\t\"import StdEnv;\\n\" +\n\t\t\"Start :: [(Int,Int)];\\n\" +\n\t\t\"Start = [(x,y) \\\\\\\\ x <- odds, y <- evens];\\n\" +\n\t\t\"where\\n\" +\n\t\t\"{\\n\" +\n\t\t\"\\todds = [1,3..9];\\n\" +\n\t\t\"\\tevens = [0,2..8];\\n\" +\n\t\t\"}\"]\n\t}\n\nbs_let =\n\t{ syntax_title = \"let expression\"\n\t, syntax_patterns = map exact [\"let\", \"in\", \"let in\"]\n\t, syntax_code = [\"let ... in ...\"]\n\t, syntax_description = \"An expression that introduces new scope.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.1\" \"_Toc311798003\"]\n\t, syntax_examples =\n\t\t[ EXs \"macro\" \"fac n = let fs = [1:1:[(fs!!(i-1)) + (fs!!(i-2)) \\\\ i <- [2..]]] in fs !! n\"\n\t\t, EXs \"macrorhs\" \"let \/\/ Multi-line let expressions\\n\\tfunction args = body\\n\\tselector = expr\\n\\t\/\/ ...\\nin expression\"\n\t\t]\n\t}\nbs_let_before =\n\t{ syntax_title = \"let before\"\n\t, syntax_patterns = map exact [\"#\", \"#!\"]\n\t, syntax_code = [\"# ... = ...\", \"#! ... = ...\"]\n\t, syntax_description = \"A {{`let`}} expression that can be defined before a guard or function body, which eases the syntax of sequential actions.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.4\" \"_Toc311798006\"]\n\t, syntax_examples =\n\t\t[ EX \"readchars :: *File -> *([Char], *File)\\nreadchars f\\n# (ok,c,f) = freadc file\\n| not ok = ([], f)\\n# (cs,f) = readchars f\\n= ([c:cs], f)\"\n\t\t]\n\t}\n\nbs_list_expressions =\n\t{ syntax_title = \"list expression\"\n\t, syntax_patterns = map exact [\"list\", \"\\\\[\\\\]\", \"\\\\[:\\\\]\", \":\", \"\\\\[\\\\w:\\\\w\\\\]\", \"\\\\['.*\"]\n\t, syntax_code = [\"[]\", \"[...:...]\", \"[..., ..., ...]\", \"['...']\"]\n\t, syntax_description =\n\t\t\"A list can be composed of individual elements or a head and a tail. Special syntax is available for creating `[{{Char}}]` lists.\\n\\n\" +\n\t\t\"See also {{dotdot}} expressions.\\n\\n\" +\n\t\t\"The colon is not an operator in Clean, because it must always be surrounded by `[` and `]`. It can therefore not be curried, flipped, etc.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798021\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"abc = ['a', 'b', 'c'] \/\/ Individual elements\"\n\t\t, \"abc = ['a':['b':['c':[]]] \/\/ Head and tail, ending with the empty list\"\n\t\t, \"abc = ['abc'] \/\/ Special syntax for [Char] lists\"\n\t\t]\n\t}\n\nbs_macro =\n\t{ syntax_title = \"macro\"\n\t, syntax_patterns = map exact [\":==\", \"macro\"]\n\t, syntax_code = [\"... :== ...\"]\n\t, syntax_description =\n\t\t\"A macro is a compile-time rewrite rule. It can be used for constants, inline subtitutions, renaming functions, conditional compilation, etc.\\n\\n\" +\n\t\t\"Macros can appear in patterns to match on constants.\"\n\t, syntax_doc_locations = [CLR 12 \"10.3\" \"_Toc311798111\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"flip f a b :== f b a \/\/ Useful for currying\"\n\t\t, \"IF_INT_64_OR_32 int64 int32 :== int64 \/\/ Conditional compilation\"\n\t\t, \"(o) infixr 9 \/\/ Function composition. Doing this at run-time would be slow\\n(o) f g :== \\\\x -> f (g x)\"\n\t\t]\n\t}\n\nbs_module =\n\t{ syntax_title = \"module heading\"\n\t, syntax_patterns = map exact [\"module\", \"definition\", \"implementation\", \"system\", \"definition module\", \"implementation module\", \"system module\"]\n\t, syntax_code = [\"[definition,implementation,system] module ...\"]\n\t, syntax_description = \"The heading of a Clean file. Definition modules describe what things are exported (dcl files), implementation modules how they are implemented (icl files).\"\n\t, syntax_doc_locations = [CLR 4 \"2.2\" \"_Toc311797983\"]\n\t, syntax_examples = map EX\n\t\t[ \"definition module StdList \/\/ Exported definitions of list functions\"\n\t\t, \"implementation module StdList \/\/ The implementations of the functions\"\n\t\t, \"module test \/\/ An implementation module without corresponding dcl\"\n\t\t, \"system module StdInt \/\/ The definitions of a module that contains foreign code (see section 2.6 of the language report)\"\n\t\t]\n\t}\n\nbs_newtype =\n\t{ syntax_title = \"Newtype definition (experimental)\"\n\t, syntax_patterns = map exact [\"=:\", \"newtype\"]\n\t, syntax_code = [\":: ... =: ... ...\"]\n\t, syntax_description = \"A newtype is a type synonym at run-time but treated as a real type at compile-time.\\n\"\n\t + \"This allows the creation of separate instances without overhead.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples =\n\t\t[ EX \":: T =: T Int\"\n\t\t, EX \":: T a =: T a\"\n\t\t]\n\t}\n\nbs_overloaded_type_variable =\n\t{ syntax_title = \"Overloaded type variable\"\n\t, syntax_patterns = map exact [\"\\\\^\", \"\\\\w\\\\^\"]\n\t, syntax_code = [\"... :: ...^\"]\n\t, syntax_description = \"A pattern match on the type of a dynamic depending on the type of the function.\"\n\t, syntax_doc_locations = [CLR 10 \"8.2.5\" \"_Toc311798087\"]\n\t, syntax_examples = [EX \"unpack :: Dynamic -> Maybe a\\nunpack (x :: a^) = Just x \/\/ Only values of type a\\nunpack _ = Nothing\"]\n\t}\n\nbs_pattern_named =\n\t{ syntax_title = \"pattern match\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = \"Give a name to the expression of a pattern to be able to use the whole expression without creating new graphs.\"\n\t, syntax_doc_locations = [CLR 5 \"3.2\" \"_Toc311797997\"]\n\t, syntax_examples = map EX\n\t\t[ \"isJustU e=:(Just _) = (True, e) \/\/ On an ADT\"\n\t\t, \":: Position = {px :: Int, py :: Int}\\ngetx p=:{px} = (px, p) \/\/ On a record; this has type :: Position -> (Int, Position)\"\n\t\t]\n\t}\n\nbs_pattern_predicate =\n\t{ syntax_title = \"pattern predicate\"\n\t, syntax_patterns = map exact [\"=:\"]\n\t, syntax_code = [\"...=:(...)\"]\n\t, syntax_description = join \" \"\n\t\t[ \"Check whether an expression matches a certain pattern (undocumented).\"\n\t\t, \"The result has type `Bool`.\"\n\t\t, \"It is not possible to introduce new identifiers this way.\"\n\t\t, \"For instance, one cannot use `if (mbx=:(Just x)) x 0`.\"\n\t\t, \"Also, `=:` can not be used in prefix form because it is not an actual operator but a builtin.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = [EX \"isSingleton l = l =: [_] \/\/ Match a value with a pattern\"]\n\t}\n\nbs_qualified_identifier =\n\t{ syntax_title = \"qualified identifier\"\n\t, syntax_patterns = map regex [\"^'.+'\", \"^qualified$\"]\n\t, syntax_code = [\"'...'. ...\"]\n\t, syntax_description = \"The identifiers of {{`qualified`}} imports must be prepended with `'...'.`, where `...` is the name of the qualified import.\"\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \"import qualified StdList\\nStart = 'StdList'.sum [0..10]\"\n\t\t, \"import qualified StdList as L\\nStart = 'L'.sum [0..10]\"\n\t\t]\n\t}\n\nbs_record_disambiguation =\n\t{ syntax_title = \"record disambiguation\"\n\t, syntax_patterns = map exact [\"\\\\|\"]\n\t, syntax_code = [\"{ ... | ... }\"]\n\t, syntax_description = join \"\\n\"\n\t\t[ \"Explicitly indicates the type of a record when it cannot be derived from the field names.\"\n\t\t]\n\t, syntax_doc_locations = []\n\t, syntax_examples = map EX\n\t\t[ \":: R1 = {x :: Int, y :: Int}\\n:: R2 = {x :: Int, y :: Int}\\nStart = {R1 | x=37, y=42}\"\n\t\t]\n\t}\n\nbs_selection_array =\n\t{ syntax_title = \"array selection\"\n\t, syntax_patterns = map exact [\"\\\\.\\\\[\\\\]\", \"\\\\.\\\\[.*\\\\]\", \"\\\\.\\\\[,.*\\\\]\", \"\\\\.\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\".[i]\", \".[i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional) array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {1,2,3,4,5,6,7,8,9,10}.[4] \/\/ Arrays are zero-indexed\"\n\t\t, \"five = {{1,2},{3,4,5},{6,7,8}}.[1,2] \/\/ This is equivalent to (...).[1].[2]\"\n\t\t]\n\t}\nbs_selection_array_unique =\n\t{ syntax_title = \"unique array selection\"\n\t, syntax_patterns = map exact [\"!\\\\[\\\\]\", \"!\\\\[.*\\\\]\", \"!\\\\[,.*\\\\]\", \"!\\\\[.*,.*\\\\]\"]\n\t, syntax_code = [\"![i]\", \"![i,j,...]\"]\n\t, syntax_description = \"Select an element from a (possibly multidimensional, possibly unique) array and return both the element and the array. The indexes must have the type {{`Int`}}.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798033\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,arr) = {1,2,3,4,5,6,7,8,9,10}![4]\"\n\t\t, \"(five,arr) = {{1,2},{3,4,5},{6,7,8}}![1,2]\"\n\t\t]\n\t}\nbs_selection_record =\n\t{ syntax_title = \"record selection\"\n\t, syntax_patterns = map exact [\"\\\\.\"]\n\t, syntax_code = [\".\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel) record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"five = {px=5, py=10}.px\"\n\t\t, \"five = {pxy={px=5, py=10}, pz=2}.pxy.px\"\n\t\t, \"five = {px=5, py=10}.Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\"\n\t\t]\n\t}\nbs_selection_record_unique =\n\t{ syntax_title = \"unique record selection\"\n\t, syntax_patterns = map exact [\"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Select a field from a (possibly multilevel, possibly unique) record and return both the field data and the record.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798050\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"(five,rec) = {px=5, py=10}!px\"\n\t\t, \"(five,rec) = {pxy={px=5, py=10}, pz=2}!pxy.px \/\/ Only the first field should have the exclamation mark\"\n\t\t, \"(five,rec) = {px=5, py=10}!Position.px \/\/ If multiple records have a field px, the type name can be used for disambiguation\\n\" +\n\t\t \" \/\/ The language report is erroneous here. It is !Position.px, not .Position!px.\"\n\t\t]\n\t}\n\nbs_strict =\n\t{ syntax_title = \"strictness annotation\"\n\t, syntax_patterns = map exact [\"strict\", \"!\"]\n\t, syntax_code = [\"!\"]\n\t, syntax_description = \"Override the lazy evaluation strategy: the argument must be evaluated to head normal form before the function is entered.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7.5\" \"_Toc311798014\", CLR 12 \"10\" \"_Toc311798103\"]\n\t, syntax_examples = [EX \"acker :: !Int !Int -> Int\"]\n\t}\n\nbs_synonym =\n\t{ syntax_title = \"synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... :== ...\"]\n\t, syntax_description = \"Defines a new type name for an existing type.\"\n\t, syntax_doc_locations = [CLR 7 \"5.3\" \"_Toc311798052\"]\n\t, syntax_examples = [EX \":: String :== {#Char}\"]\n\t}\nbs_synonym_abstract =\n\t{ syntax_title = \"abstract synonym type definition\"\n\t, syntax_patterns = map exact [\"synonym\", \":==\"]\n\t, syntax_code = [\":: ... (:== ...)\"]\n\t, syntax_description = \"Defines a new type name for an existing type, while the type behaves as an abstract type for the programmer. This allows compiler optimisations on abstract types.\"\n\t, syntax_doc_locations = [CLR 7 \"5.4.1\" \"_Toc311798054\"]\n\t, syntax_examples = [EX \":: Stack a (:== [a])\"]\n\t}\n\nbs_type_definition =\n\t{ syntax_title = \"type definition\"\n\t, syntax_patterns = map exact [\"::\", \"=\", \"\\\\|\"]\n\t, syntax_code = [\":: ...\"]\n\t, syntax_description = \"Defines a new type. There are too many possibilities to list hear; see the documentation.\"\n\t, syntax_doc_locations = [CLR 7 \"5\" \"_Toc311798038\"]\n\t, syntax_examples = map EX\n\t\t[ join \"\\n\\t\" [\":: Day \/\/ An algebraic data type\",\"= Mon\",\"| Tue\",\"| Wed\",\"| Thu\",\"| Fri\",\"| Sat\",\"| Sun\"]\n\t\t, \":: Position = \/\/ A record type\\n\\t{ x :: Int\\n\\t, y :: Int\\n\\t}\"\n\t\t]\n\t}\n\nbs_type_specification =\n\t{ syntax_title = \"type specification\"\n\t, syntax_patterns = map exact [\"::\"]\n\t, syntax_code = [\"... :: ...\"]\n\t, syntax_description = \"Specifies the type of a function.\"\n\t, syntax_doc_locations = [CLR 5 \"3.7\" \"_Toc311798009\"]\n\t, syntax_examples = map EX\n\t\t[ \"map :: (a -> b) [a] -> [b] \/\/ map has arity 2\\nmap f [] = []\\nmap f [x:xs] = [f x:map f xs]\"\n\t\t, \"map :: (a -> b) -> [a] -> [b] \/\/ map has arity 1\\nmap f = \\\\xs -> case xs of\\n\\t[] -> []\\n\\t[x:xs] -> [f x:map f xs]\"\n\t\t]\n\t}\n\nbs_unique =\n\t{ syntax_title = \"uniqueness annotation\"\n\t, syntax_patterns = map exact [\"\\\\*\", \"\\\\.\", \"\\\\w:\", \"\\\\[.*<=.*\\\\]\", \",\", \"<=\"]\n\t, syntax_code =\n\t\t[ \"*...\"\n\t\t, \". ...\"\n\t\t, \"...:..., [...<=...], [...<=...], ...\"\n\t\t]\n\t, syntax_description = join \" \"\n\t\t[ \"Annotates a type with its uniqueness.\"\n\t\t, \"A type can either be unique (`*`), not unique (not annotated), possibly unique (`.`) or relatively unique (identifier and `, [...<=...]` after the type context).\"\n\t\t, \"Because uniqueness is binary, there is only one case where `[u<=v]` is not satisfied; when `u` is unique but `v` is not.\"\n\t\t, \"\\n\\nOn function types, *uniqueness propagation* is implicit (see section 9.2 of the language report).\"\n\t\t, \"However, when using unique types in a function or an ADT this has to be made explicit; for instance:\"\n\t\t, \"`T = T (Int, *File)` has to be `T = T *(Int, *File)`.\"\n\t\t, \"Functions have to be split up into arity 1 and the subfunctions must be annotated as well; for instance:\"\n\t\t, \"`T = T (Int *Int -> *Int)` has to be `T = T (Int -> *(*Int -> *Int))`.\"\n\t\t]\n\t, syntax_doc_locations = [CLR 11 \"9.1\" \"_Toc311798093\"]\n\t, syntax_examples = map EX\n\t\t[ \"Start :: *World -> *World \/\/ World is unique\"\n\t\t, \"copyArray :: *(a e) -> *(*a e, *a e) | Array a e \/\/ Add parentheses when needed\"\n\t\t, \"f :: .a -> .a \/\/ f works on unique and non-unique values\"\n\t\t, \"f :: v:a u:b -> u:b, [v<=u] \/\/ f works when a is less unique than b\"\n\t\t]\n\t}\n\nbs_update_array =\n\t{ syntax_title = \"array update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\{.*&.*\\\\[.*].*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ a & [i]=x, [j]=y, ... } \/\/ Updates a by setting index i to x, j to y, ...\"\n\t\t, \"# a & [i]=x, [j]=y, ... \/\/ Same as # a = {a & [i]=x, [j]=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t, \"{ a & [i]=i \\\\\\\\ i <- [0,2..9] } \/\/ Fancy things can be done if you combine this with a ZF-expression. E.g. give the first 5 even indices the value of their index\"\n\t\t]\n\t, syntax_description = \"Updates an array by creating a copy and replacing one or more elements.\"\n\t, syntax_doc_locations = [CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = []\n\t}\nbs_update_record =\n\t{ syntax_title = \"record update\"\n\t, syntax_patterns = map exact [\"&\", \"\\\\|\", \"\\\\{.*&.*=.*\\\\}\"]\n\t, syntax_code =\n\t\t[ \"{ r & f1=x, f2=y, ... } \/\/ Updates r by setting f1 to x, f2 to y, ...\"\n\t\t, \"{ MyRecord | r & f1=x, f2=y, ... } \/\/ explicitly stating the type\"\n\t\t, \"# r & f1=x, f2=y, ... \/\/ Same as # r = {r & f1=x, f2=y, ...}\" \/\/ See https:\/\/clean.cs.ru.nl\/Clean_2.3\n\t\t]\n\t, syntax_description = \"Updates a record by creating a copy and replacing one or more fields.\"\n\t, syntax_doc_locations = [CLR 7 \"5.2.1\" \"_Toc311798049\"]\n\t, syntax_examples = []\n\t}\n\nbs_where_class =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the members of a {{`class`}} definition.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"class Arith a \/\/ Class definition\\nwhere\\n\\t(+) infixl 6 :: a a -> a\\n\\t(-) infixl 6 :: a a -> a\"]\n\t}\nbs_where_instance =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces the implementation of an {{`instance`}}.\"\n\t, syntax_doc_locations = [CLR 8 \"6.1\" \"_Toc311798056\"]\n\t, syntax_examples = [EX \"instance Arith Int \/\/ Instance definition\\nwhere\\n\\t(+) x y = \/\/ ...\\n\\t(-) x y = \/\/ ...\"]\n\t}\nbs_where_local =\n\t{ syntax_title = \"where\"\n\t, syntax_patterns = map exact [\"where\"]\n\t, syntax_code = [\"where\"]\n\t, syntax_description = \"Introduces local definitions. For guard-local definitions, see {{`with`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.2\" \"_Toc311798004\"]\n\t, syntax_examples = [EXs \"macro\" \"primes = sieve [2..] \/\/ Local definitions\\nwhere\\n\\tsieve [pr:r] = [pr:sieve (filter pr r)]\"]\n\t}\n\nbs_with =\n\t{ syntax_title = \"with\"\n\t, syntax_patterns = map exact [\"with\"]\n\t, syntax_code = [\"with\"]\n\t, syntax_description = \"Introduces guard-local definitions. For function-local definitions, see {{`where`}}.\"\n\t, syntax_doc_locations = [CLR 5 \"3.5.3\" \"_Toc311798005\"]\n\t, syntax_examples = [EXs \"macro\" \"f x y\\n| guard1 = alt1\\n\\twith local = expr1\\n| guard2 = alt2\\n\\twith local = expr2\"]\n\t}\n\nbs_zf =\n\t{ syntax_title = \"list comprehension\"\n\t, syntax_patterns = map exact [\"ZF-expression\", \"ZF\", \"zf\", \"*comprehension\", \"<-\", \"<\\\\|-\", \"<-:\", \"\\\\\\\\\\\\\\\\\", \",\", \"&\", \"\\\\|\"]\n\t, syntax_code =\n\t\t[ \"[... \\\\\\\\ ... <- ...]\"\n\t\t, \"{... \\\\\\\\ ... <- ...}\"\n\t\t]\n\t, syntax_description = \"Constructs a list or array composed of elements drawn from other lists or arrays.\"\n\t, syntax_doc_locations = [CLR 6 \"4.2.1\" \"_Toc311798024\", CLR 6 \"4.4.1\" \"_Toc311798032\"]\n\t, syntax_examples = map (EXs \"macro\")\n\t\t[ \"cartesian = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [10,20]] \/\/ Cartesian product: (1,10), (1,20), (2,10), (2,20), (3,10), (3,20)\"\n\t\t, \"zip xs ys = [(x,y) \\\\\\\\ x <- xs & y <- ys] \/\/ Pairwise zip through the lists\"\n\t\t, \"filter f xs = [x \\\\\\\\ x <- xs | f x] \/\/ Guard to add conditions\"\n\t\t, \"catMaybes ms = [x \\\\\\\\ Just x <- ms] \/\/ Pattern matching in the selector\"\n\t\t, \"triangle = [(x,y) \\\\\\\\ x <- [1,2,3], y <- [1..x]] \/\/ Reusing x in the next generator: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3)\"\n\t\t, \"arrToList a = [x \\\\\\\\ x <-: a] \/\/ <-: to draw elements from an array\"\n\t\t, \"listToArr l = {x \\\\\\\\ x <- l} \/\/ {..} to create an array\"\n\t\t, \"castList xs = [|x \\\\\\\\ x <|- xs] \/\/ The two pipe characters make both xs and the result overloaded lists\"\n\t\t]\n\t}\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"bdaf51795b16a54073d0d85823055d43f16f63a6","subject":"Correct ABC documentation for push*; add documentation for build*","message":"Correct ABC documentation for push*; add documentation for build*\n","repos":"clean-cloogle\/cloogle.org,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle","old_file":"backend\/BuiltinABCInstructions.icl","new_file":"backend\/BuiltinABCInstructions.icl","new_contents":"implementation module BuiltinABCInstructions\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle\n\nimport CloogleDB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_ccall\n\t, i_centry\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t, d_d\n\t, d_o\n\t: arith_instructions ++\n\t pushes ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_ccall :: ABCInstructionEntry\ni_ccall =\n\t{ zero\n\t& aie_instruction = \"ccall\"\n\t, aie_arguments = [LABEL, STRING]\n\t, aie_description = join \"\\n\"\n\t\t[ \"Calls a C function.\"\n\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t, \"\\n\"\n\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t, \"- sep can be either `-` or `:`.\"\n\t\t, \"- flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t, \"- input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t, \"- output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t, \"- state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t, \"\\n\"\n\t\t, \"Input, output and state argument types can be:\"\n\t\t, \"- `I` for integers\"\n\t\t, \"- `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t, \"- [`Rr`] for reals\"\n\t\t, \"- `S` for Clean Strings (`{#Char}`).\"\n\t\t, \"- `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}})\"\n\t\t, \"- `A` for A-stack elements (e.g. used for `*World`, a boxed integer under the hood)\"\n\t\t, \"- [`OF`] for function pointers\"\n\t\t, \"- `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t]\n\t}\n\ni_centry :: ABCInstructionEntry\ni_centry =\n\t{ zero\n\t& aie_instruction = \"centry\"\n\t, aie_arguments = [LABEL, LABEL, STRING]\n\t, aie_description = join \"\\n\"\n\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t, \"The first label is the name of the C function to generate.\"\n\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t, \"The string argument indicates the type.\"\n\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t]\n\t}\n\ni_halt :: ABCInstructionEntry\ni_halt =\n\t{ zero\n\t& aie_instruction = \"halt\"\n\t, aie_description = \"Terminates the program immediately.\"\n\t}\n\ni_instruction :: ABCInstructionEntry\ni_instruction =\n\t{ zero\n\t& aie_instruction = \"instruction\"\n\t, aie_arguments = [INT]\n\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t}\n\ni_load_i :: ABCInstructionEntry\ni_load_i =\n\t{ zero\n\t& aie_instruction = \"load_i\"\n\t, aie_arguments = [INT]\n\t, aie_description = join \"\\n\\n\"\n\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t]\n\t}\n\ni_load_si16 :: ABCInstructionEntry\ni_load_si16 =\n\t{ zero\n\t& aie_instruction = \"load_si16\"\n\t, aie_arguments = [INT]\n\t, aie_description = join \"\\n\\n\"\n\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t]\n\t}\n\ni_load_si32 :: ABCInstructionEntry\ni_load_si32 =\n\t{ zero\n\t& aie_instruction = \"load_si32\"\n\t, aie_arguments = [INT]\n\t, aie_description = join \"\\n\\n\"\n\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t]\n\t}\n\ni_load_ui8 :: ABCInstructionEntry\ni_load_ui8 =\n\t{ zero\n\t& aie_instruction = \"load_ui8\"\n\t, aie_arguments = [INT]\n\t, aie_description = join \"\\n\\n\"\n\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t]\n\t}\n\ni_no_op :: ABCInstructionEntry\ni_no_op =\n\t{ zero\n\t& aie_instruction = \"no_op\"\n\t, aie_description = join \"\\n\"\n\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t, \"```clean\"\n\t\t, \"cast :: .a -> .b\"\n\t\t, \"cast _ = code {\"\n\t\t, \"\\tno_op\"\n\t\t, \"}\"\n\t\t, \"```\"\n\t\t]\n\t}\n\nd_d :: ABCInstructionEntry\nd_d =\n\t{ zero\n\t& aie_instruction = \".d\"\n\t, aie_arguments = [INT, INT, STRING_]\n\t, aie_description = concat\n\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t]\n\t}\n\nd_o :: ABCInstructionEntry\nd_o =\n\t{ zero\n\t& aie_instruction = \".o\"\n\t, aie_arguments = [INT, INT, STRING_]\n\t, aie_description = concat\n\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t]\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\npushes :: [ABCInstructionEntry]\npushes =\n\t[ push \"Bool\" BOOL\n\t, push \"Char\" CHAR\n\t, push \"Int\" INT\n\t, push \"Real\" REAL\n\t, push_a \"Bool\"\n\t, push_a \"Char\"\n\t, push_a \"Int\"\n\t, push_a \"Real\"\n\t, build \"Bool\" BOOL\n\t, build \"Char\" CHAR\n\t, build \"Int\" INT\n\t, build \"Real\" REAL\n\t, build_b \"Bool\"\n\t, build_b \"Char\"\n\t, build_b \"Int\"\n\t, build_b \"Real\"\n\t]\nwhere\n\tpush :: !String !ABCArgument -> ABCInstructionEntry\n\tpush type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the B-stack.\"\n\t\t}\n\n\tpush_a :: !String -> ABCInstructionEntry\n\tpush_a type =\n\t\t{ zero\n\t\t& aie_instruction = \"push\" + {type.[0]} + \"_a\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Pushes the \" + type + \" from the nth position on the A-stack to the B-stack.\"\n\t\t}\n\n\tbuild :: !String !ABCArgument -> ABCInstructionEntry\n\tbuild type arg =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]}\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the argument as value on the A-stack.\"\n\t\t}\n\n\tbuild_b :: !String -> ABCInstructionEntry\n\tbuild_b type =\n\t\t{ zero\n\t\t& aie_instruction = \"build\" + {type.[0]} + \"_b\"\n\t\t, aie_arguments = [INT]\n\t\t, aie_description = \"Builds a \" + type + \"-node with the value on the nth position of the B-stack on the A-stack.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildAC\"\n\t, \"buildF_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create\"\n\t, \"create_array\"\n\t, \"create_array_\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqB_a\"\n\t, \"eqB_b\"\n\t, \"eqC_a\"\n\t, \"eqC_b\"\n\t, \"eqD_b\"\n\t, \"eqI_a\"\n\t, \"eqI_b\"\n\t, \"eqR_a\"\n\t, \"eqR_b\"\n\t, \"eqAC_a\"\n\t, \"eq_desc\"\n\t, \"eq_desc_b\"\n\t, \"eq_nulldesc\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"get_node_arity\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_false\"\n\t, \"jmp_not_eqZ\"\n\t, \"jmp_true\"\n\t, \"jrsr\"\n\t, \"jsr\"\n\t, \"jsr_ap\"\n\t, \"jsr_eval\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"pop_a\"\n\t, \"pop_b\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_a\"\n\t, \"push_b\"\n\t, \"push_a_b\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_t_r_a\"\n\t, \"push_t_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_t\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"rtn\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".depend\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".end\"\n\t, \".endinfo\"\n\t, \".export\"\n\t, \".keep\"\n\t, \".inline\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".module\"\n\t, \".n\"\n\t, \".nu\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".start\"\n\t, \".string\"\n\t]\n","old_contents":"implementation module BuiltinABCInstructions\n\nimport _SystemArray\nimport StdList\nimport StdMisc\n\nimport Text\n\nimport Cloogle\n\nimport CloogleDB\n\nbuiltin_abc_instructions :: [ABCInstructionEntry]\nbuiltin_abc_instructions =\n\t[ i_ccall\n\t, i_centry\n\t, i_halt\n\t, i_instruction\n\t, i_load_i\n\t, i_load_si16\n\t, i_load_si32\n\t, i_load_ui8\n\t, i_no_op\n\t, d_d\n\t, d_o\n\t: arith_instructions ++\n\t pushes ++\n\t [{zero & aie_instruction=i} \\\\ i <- other_instructions]\n\t]\n\ninstance zero ABCInstructionEntry\nwhere\n\tzero =\n\t\t{ aie_instruction = undef\n\t\t, aie_arguments = []\n\t\t, aie_description = \"There is no documentation for this ABC instruction yet.\"\n\t\t}\n\nLABEL :== ABCArgument ABCTypeLabel False\nLABEL_ :== ABCArgument ABCTypeLabel True\nSTRING :== ABCArgument ABCTypeString False\nSTRING_ :== ABCArgument ABCTypeString True\nBOOL :== ABCArgument ABCTypeBool False\nBOOL_ :== ABCArgument ABCTypeBool True\nCHAR :== ABCArgument ABCTypeChar False\nCHAR_ :== ABCArgument ABCTypeChar True\nINT :== ABCArgument ABCTypeInt False\nINT_ :== ABCArgument ABCTypeInt True\nREAL :== ABCArgument ABCTypeReal False\nREAL_ :== ABCArgument ABCTypeReal True\n\ni_ccall :: ABCInstructionEntry\ni_ccall =\n\t{ zero\n\t& aie_instruction = \"ccall\"\n\t, aie_arguments = [LABEL, STRING]\n\t, aie_description = join \"\\n\"\n\t\t[ \"Calls a C function.\"\n\t\t, \"Some of this is documented in https:\/\/svn.cs.ru.nl\/repos\/clean-tools\/trunk\/htoclean\/CallingCFromClean.html\"\n\t\t, \"The first argument is the name of the function, the second is the signature.\"\n\t\t, \"\\n\"\n\t\t, \"The signature has to be of the form `flags?input?sep output(sep state)?`, where\"\n\t\t, \"- sep can be either `-` or `:`.\"\n\t\t, \"- flags can be `G` and\/or `P`. `G` saves the state in global variables and is needed when the called C function will call Clean functions. `P` lets the callee pop arguments (necessary on 32-bit Windows).\"\n\t\t, \"- input is a number of input argument types (allowed: `IpRrSsAOF`).\"\n\t\t, \"- output is a number of output argument types (allowed: `VIpRrSsAOF`).\"\n\t\t, \"- state is a carried state that is not passed to the C function, for example used to thread {{`World`}} in ccalls (allowed: `IpRSA`).\"\n\t\t, \"\\n\"\n\t\t, \"Input, output and state argument types can be:\"\n\t\t, \"- `I` for integers\"\n\t\t, \"- `p` for pointers (e.g. from {{`System.Pointer`}}; on most systems this is identical to `I`)\"\n\t\t, \"- [`Rr`] for reals\"\n\t\t, \"- `S` for Clean Strings (`{#Char}`).\"\n\t\t, \"- `s` for the characters of a Clean String (handy to use in conjuction with {{`packString`}})\"\n\t\t, \"- `A` for A-stack elements (e.g. used for `*World`, a boxed integer under the hood)\"\n\t\t, \"- [`OF`] for function pointers\"\n\t\t, \"- `V` for `void`, packs the following argument types in a tuple (e.g. `VIR` means `(Int, Real)`)\"\n\t\t]\n\t}\n\ni_centry :: ABCInstructionEntry\ni_centry =\n\t{ zero\n\t& aie_instruction = \"centry\"\n\t, aie_arguments = [LABEL, LABEL, STRING]\n\t, aie_description = join \"\\n\"\n\t\t[ \"Adds code to call a Clean function from C.\"\n\t\t, \"Usually it is not needed to write this instruction yourself.\"\n\t\t, \"It is generated with the `foreign export` construct.\\n\"\n\t\t, \"The first label is the name of the C function to generate.\"\n\t\t, \"The second label is the Clean function to link it to.\\n\"\n\t\t, \"The string argument indicates the type.\"\n\t\t, \"For more information, see {{`ccall`}}.\"\n\t\t]\n\t}\n\ni_halt :: ABCInstructionEntry\ni_halt =\n\t{ zero\n\t& aie_instruction = \"halt\"\n\t, aie_description = \"Terminates the program immediately.\"\n\t}\n\ni_instruction :: ABCInstructionEntry\ni_instruction =\n\t{ zero\n\t& aie_instruction = \"instruction\"\n\t, aie_arguments = [INT]\n\t, aie_description = \"Adds the raw argument as a word in the generated object file.\"\n\t}\n\ni_load_i :: ABCInstructionEntry\ni_load_i =\n\t{ zero\n\t& aie_instruction = \"load_i\"\n\t, aie_arguments = [INT]\n\t, aie_description = join \"\\n\\n\"\n\t\t[ \"Take the top of the B-stack as a pointer and read an integer from that pointer with the argument as offset.\"\n\t\t, \"See also {{`load_si16`}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t]\n\t}\n\ni_load_si16 :: ABCInstructionEntry\ni_load_si16 =\n\t{ zero\n\t& aie_instruction = \"load_si16\"\n\t, aie_arguments = [INT]\n\t, aie_description = join \"\\n\\n\"\n\t\t[ \"Take the top of the B-stack as a pointer and read a 16-bit signed integer from that pointer with the argument as offset.\"\n\t\t, \"See also {{`load_i}}, {{`load_si32`}}, {{`load_ui8`}}.\"\n\t\t]\n\t}\n\ni_load_si32 :: ABCInstructionEntry\ni_load_si32 =\n\t{ zero\n\t& aie_instruction = \"load_si32\"\n\t, aie_arguments = [INT]\n\t, aie_description = join \"\\n\\n\"\n\t\t[ \"Take the top of the B-stack as a pointer and read a 32-bit signed integer from that pointer with the argument as offset.\"\n\t\t, \"This instruction is only available on 64-bit systems. On 32-bit systems, {{`load_i`}} has the same effect.\"\n\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_ui8`}}.\"\n\t\t]\n\t}\n\ni_load_ui8 :: ABCInstructionEntry\ni_load_ui8 =\n\t{ zero\n\t& aie_instruction = \"load_ui8\"\n\t, aie_arguments = [INT]\n\t, aie_description = join \"\\n\\n\"\n\t\t[ \"Take the top of the B-stack as a pointer and read a 8-bit unsigned integer from that pointer with the argument as offset.\"\n\t\t, \"See also {{`load_i`}}, {{`load_si16`}}, {{`load_si32`}}.\"\n\t\t]\n\t}\n\ni_no_op :: ABCInstructionEntry\ni_no_op =\n\t{ zero\n\t& aie_instruction = \"no_op\"\n\t, aie_description = join \"\\n\"\n\t\t[ \"Do nothing. This is for example useful in the `cast` function:\\n\"\n\t\t, \"```clean\"\n\t\t, \"cast :: .a -> .b\"\n\t\t, \"cast _ = code {\"\n\t\t, \"\\tno_op\"\n\t\t, \"}\"\n\t\t, \"```\"\n\t\t]\n\t}\n\nd_d :: ABCInstructionEntry\nd_d =\n\t{ zero\n\t& aie_instruction = \".d\"\n\t, aie_arguments = [INT, INT, STRING_]\n\t, aie_description = concat\n\t\t[ \"Indicates how many stack elements are on the stack when a jump follows.\"\n\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t]\n\t}\n\nd_o :: ABCInstructionEntry\nd_o =\n\t{ zero\n\t& aie_instruction = \".o\"\n\t, aie_arguments = [INT, INT, STRING_]\n\t, aie_description = concat\n\t\t[ \"Indicates how many stack elements are 'given back' to a calling function when a {{`rtn`}} follows.\"\n\t\t, \"The first integer is the number of elements on the A-stack; the second that of B-stack elements.\"\n\t\t, \"The optional third argument indicates the type of the B-stack elements, e.g. `bbi` for two booleans and an integer.\"\n\t\t]\n\t}\n\narith_instructions :: [ABCInstructionEntry]\narith_instructions =\n\t[ arith1 \"absR\" \"Real\" \"absolute value\"\n\t, arith1 \"acosR\" \"Real\" \"arccosine\"\n\t, arith1 \"asinR\" \"Real\" \"arcsine\"\n\t, arith1 \"atanR\" \"Real\" \"arctangent\"\n\t, arith1 \"cosR\" \"Real\" \"cosine\"\n\t, arith1 \"entierR\" \"Real\" \"(Int) entier (floor)\"\n\t, arith1 \"expR\" \"Real\" \"exponential function (e^r)\"\n\t, arith1 \"lnR\" \"Real\" \"natural logarithm\"\n\t, arith1 \"log10R\" \"Real\" \"base-10 logarithm\"\n\t, arith1 \"notB\" \"Bool\" \"logical negation\"\n\t, arith1 \"sinR\" \"Real\" \"sine\"\n\t, arith1 \"sqrtR\" \"Real\" \"square root\"\n\t, arith1 \"tanR\" \"Real\" \"tangent\"\n\n\t, op1 \"decI\" \"Int\" \"Decrements\"\n\t, op1 \"incI\" \"Int\" \"Increments\"\n\t, op1 \"negI\" \"Int\" \"Negates\"\n\t, op1 \"negR\" \"Real\" \"Negates\"\n\t, op1 \"not%\" \"Int\" \"Bitwise negates\"\n\n\t, op2 \"addI\" \"Int\" \"Sums\"\n\t, op2 \"addR\" \"Real\" \"Sums\"\n\t, op2 \"andB\" \"Bool\" \"Logically conjuncts\"\n\t, op2 \"and%\" \"Int\" \"Bitwise conjuncts\"\n\t, op2 \"divI\" \"Int\" \"Divides\"\n\t, op2 \"divR\" \"Real\" \"Divides\"\n\t, op2 \"eqB\" \"Bool\" \"Checks equality on\"\n\t, op2 \"eqC\" \"Char\" \"Checks equality on\"\n\t, op2 \"eqI\" \"Int\" \"Checks equality on\"\n\t, op2 \"eqR\" \"Real\" \"Checks equality on\"\n\t, op2 \"gtC\" \"Char\" \"Checks greater-than on\"\n\t, op2 \"gtI\" \"Int\" \"Checks greater-than on\"\n\t, op2 \"gtR\" \"Real\" \"Checks greater-than on\"\n\t, op2 \"ltC\" \"Char\" \"Checks less-than on\"\n\t, op2 \"ltI\" \"Int\" \"Checks less-than on\"\n\t, op2 \"ltR\" \"Real\" \"Checks less-than on\"\n\t, op2 \"mulI\" \"Int\" \"Multiplies\"\n\t, op2 \"mulR\" \"Real\" \"Multiplies\"\n\t, op2 \"orB\" \"Bool\" \"Logically disjuncts\"\n\t, op2 \"or%\" \"Int\" \"Bitwise disjuncts\"\n\t, op2 \"powR\" \"Real\" \"Raises to the power on\"\n\t, op2 \"remI\" \"Int\" \"Computes the remainder after division of\"\n\t, op2 \"rotl%\" \"Int\" \"Bitwise left-rotate on\"\n\t, op2 \"rotr%\" \"Int\" \"Bitwise right-rotate on\"\n\t, op2 \"shiftl%\" \"Int\" \"Bitwise left-shift on\"\n\t, op2 \"shiftr%\" \"Int\" \"Bitwise right-shift on\"\n\t, op2 \"subI\" \"Int\" \"Subtracts\"\n\t, op2 \"subR\" \"Real\" \"Subtracts\"\n\t, op2 \"xor%\" \"Int\" \"Bitwise XOR on\"\n\n\t, convert \"CtoI\" \"Char\" \"Int\"\n\t, convert \"CtoAC\" \"Char\" \"String\"\n\t, convert \"ItoC\" \"Int\" \"Char\"\n\t, convert \"ItoR\" \"Int\" \"Real\"\n\t, convert \"RtoI\" \"Real\" \"Int\"\n\t]\nwhere\n\tarith1 :: !String !String !String -> ABCInstructionEntry\n\tarith1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Computes the \" + description + \" of the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top1 :: !String !String !String -> ABCInstructionEntry\n\top1 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the \" + type + \" on top of the B-stack.\"\n\t\t}\n\n\top2 :: !String !String !String -> ABCInstructionEntry\n\top2 instr type description =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = description + \" the two \" + type + \"s on top of the B-stack.\"\n\t\t}\n\n\tconvert :: !String !String !String -> ABCInstructionEntry\n\tconvert instr fr to =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_description = \"Converts the \" + fr + \" on top of the B-stack to \" + to + \".\"\n\t\t}\n\npushes :: [ABCInstructionEntry]\npushes =\n\t[ push \"pushB\" \"Char\" BOOL 'B'\n\t, push \"pushB_a\" \"Char\" BOOL 'A'\n\t, push \"pushC\" \"Char\" CHAR 'B'\n\t, push \"pushC_a\" \"Char\" CHAR 'A'\n\t, push \"pushI\" \"Int\" INT 'B'\n\t, push \"pushI_a\" \"Int\" INT 'A'\n\t, push \"pushR\" \"Real\" REAL 'B'\n\t, push \"pushR_a\" \"Real\" REAL 'A'\n\t]\nwhere\n\tpush :: !String !String !ABCArgument !Char -> ABCInstructionEntry\n\tpush instr type arg stack =\n\t\t{ zero\n\t\t& aie_instruction = instr\n\t\t, aie_arguments = [arg]\n\t\t, aie_description = \"Pushes the \" + type + \" argument to the \" + {stack} + \"-stack.\"\n\t\t}\n\n\/**\n * Instructions without documentation yet\n *\/\nother_instructions :: [String]\nother_instructions =\n\t[ \"add_args\"\n\t, \"addLU\"\n\t, \"build\"\n\t, \"buildB\"\n\t, \"buildC\"\n\t, \"buildI\"\n\t, \"buildR\"\n\t, \"buildAC\"\n\t, \"buildB_b\"\n\t, \"buildC_b\"\n\t, \"buildF_b\"\n\t, \"buildI_b\"\n\t, \"buildR_b\"\n\t, \"buildh\"\n\t, \"build_r\"\n\t, \"build_u\"\n\t, \"catS\"\n\t, \"call\"\n\t, \"cmpS\"\n\t, \"ceilingR\"\n\t, \"copy_graph\"\n\t, \"code_channelP\"\n\t, \"create\"\n\t, \"create_array\"\n\t, \"create_array_\"\n\t, \"create_channel\"\n\t, \"currentP\"\n\t, \"del_args\"\n\t, \"divLU\"\n\t, \"divU\"\n\t, \"eqB_a\"\n\t, \"eqB_b\"\n\t, \"eqC_a\"\n\t, \"eqC_b\"\n\t, \"eqD_b\"\n\t, \"eqI_a\"\n\t, \"eqI_b\"\n\t, \"eqR_a\"\n\t, \"eqR_b\"\n\t, \"eqAC_a\"\n\t, \"eq_desc\"\n\t, \"eq_desc_b\"\n\t, \"eq_nulldesc\"\n\t, \"eq_symbol\"\n\t, \"exit_false\"\n\t, \"fill\"\n\t, \"fill1\"\n\t, \"fill2\"\n\t, \"fill3\"\n\t, \"fill1_r\"\n\t, \"fill2_r\"\n\t, \"fill3_r\"\n\t, \"fillcaf\"\n\t, \"fillcp\"\n\t, \"fillcp_u\"\n\t, \"fill_u\"\n\t, \"fillh\"\n\t, \"fillB\"\n\t, \"fillB_b\"\n\t, \"fillC\"\n\t, \"fillC_b\"\n\t, \"fillF_b\"\n\t, \"fillI\"\n\t, \"fillI_b\"\n\t, \"fillR\"\n\t, \"fillR_b\"\n\t, \"fill_a\"\n\t, \"fill_r\"\n\t, \"floordivI\"\n\t, \"getWL\"\n\t, \"get_desc_arity\"\n\t, \"get_desc_flags_b\"\n\t, \"get_desc0_number\"\n\t, \"get_node_arity\"\n\t, \"gtU\"\n\t, \"in\"\n\t, \"is_record\"\n\t, \"ItoP\"\n\t, \"jmp\"\n\t, \"jmp_ap\"\n\t, \"jmp_ap_upd\"\n\t, \"jmp_upd\"\n\t, \"jmp_eval\"\n\t, \"jmp_eval_upd\"\n\t, \"jmp_false\"\n\t, \"jmp_not_eqZ\"\n\t, \"jmp_true\"\n\t, \"jrsr\"\n\t, \"jsr\"\n\t, \"jsr_ap\"\n\t, \"jsr_eval\"\n\t, \"ltU\"\n\t, \"modI\"\n\t, \"mulUUL\"\n\t, \"new_ext_reducer\"\n\t, \"new_int_reducer\"\n\t, \"newP\"\n\t, \"out\"\n\t, \"pop_a\"\n\t, \"pop_b\"\n\t, \"print\"\n\t, \"printD\"\n\t, \"print_char\"\n\t, \"print_int\"\n\t, \"print_real\"\n\t, \"print_r_arg\"\n\t, \"print_sc\"\n\t, \"print_symbol\"\n\t, \"print_symbol_sc\"\n\t, \"pushcaf\"\n\t, \"push_finalizers\"\n\t, \"pushA_a\"\n\t, \"pushD\"\n\t, \"pushD_a\"\n\t, \"pushF_a\"\n\t, \"pushL\"\n\t, \"pushLc\"\n\t, \"pushzs\"\n\t, \"push_a\"\n\t, \"push_b\"\n\t, \"push_a_b\"\n\t, \"push_arg\"\n\t, \"push_arg_b\"\n\t, \"push_args\"\n\t, \"push_args_u\"\n\t, \"push_array\"\n\t, \"push_arraysize\"\n\t, \"push_b_a\"\n\t, \"push_node\"\n\t, \"push_node_u\"\n\t, \"push_a_r_args\"\n\t, \"push_t_r_a\"\n\t, \"push_t_r_args\"\n\t, \"push_r_args\"\n\t, \"push_r_args_a\"\n\t, \"push_r_args_b\"\n\t, \"push_r_args_u\"\n\t, \"push_r_arg_D\"\n\t, \"push_r_arg_t\"\n\t, \"push_r_arg_u\"\n\t, \"push_wl_args\"\n\t, \"pushZ\"\n\t, \"pushZR\"\n\t, \"putWL\"\n\t, \"randomP\"\n\t, \"release\"\n\t, \"remU\"\n\t, \"replace\"\n\t, \"repl_arg\"\n\t, \"repl_args\"\n\t, \"repl_args_b\"\n\t, \"repl_r_args\"\n\t, \"repl_r_args_a\"\n\t, \"rtn\"\n\t, \"select\"\n\t, \"send_graph\"\n\t, \"send_request\"\n\t, \"set_continue\"\n\t, \"set_defer\"\n\t, \"set_entry\"\n\t, \"set_finalizers\"\n\t, \"setwait\"\n\t, \"shiftrU\"\n\t, \"sincosR\"\n\t, \"sliceS\"\n\t, \"stop_reducer\"\n\t, \"subLU\"\n\t, \"addIo\"\n\t, \"mulIo\"\n\t, \"subIo\"\n\t, \"suspend\"\n\t, \"testcaf\"\n\t, \"truncateR\"\n\t, \"update_a\"\n\t, \"updatepop_a\"\n\t, \"update_b\"\n\t, \"updatepop_b\"\n\t, \"updateS\"\n\t, \"update\"\n\t, \".algtype\"\n\t, \".caf\"\n\t, \".code\"\n\t, \".comp\"\n\t, \".a\"\n\t, \".depend\"\n\t, \".desc\"\n\t, \".desc0\"\n\t, \".descn\"\n\t, \".descexp\"\n\t, \".descs\"\n\t, \".end\"\n\t, \".endinfo\"\n\t, \".export\"\n\t, \".keep\"\n\t, \".inline\"\n\t, \".impdesc\"\n\t, \".implab\"\n\t, \".implib\"\n\t, \".impmod\"\n\t, \".impobj\"\n\t, \".module\"\n\t, \".n\"\n\t, \".nu\"\n\t, \".newlocallabel\"\n\t, \".n_string\"\n\t, \".pb\"\n\t, \".pd\"\n\t, \".pe\"\n\t, \".pl\"\n\t, \".pld\"\n\t, \".pn\"\n\t, \".pt\"\n\t, \".record\"\n\t, \".start\"\n\t, \".string\"\n\t]\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"0327374d62aa54bdb34b43ab464c8db43a72e204","subject":"cleanup","message":"cleanup\n","repos":"clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,dopefishh\/cloogle,clean-cloogle\/cloogle.org,clean-cloogle\/cloogle,clean-cloogle\/cloogle.org,dopefishh\/cloogle","old_file":"builddb.icl","new_file":"builddb.icl","new_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}\n\n\/\/ StdEnv\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nfrom Text import class Text(concat), instance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String\nimport CoclUtils\n\n\/\/ frontend\n\/\/import Heap, compile, parse, predef\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents), ::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr, ::Position(NoPos), ::Module{mod_ident,mod_defs}, ::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class), ::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType, ::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_types}, ::Type, ::ClassDef{class_ident,class_args}, ::TypeVar\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = {\n\thelp :: Bool,\n\tversion :: Bool,\n\troot :: String,\n\tlibs :: [String]}\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ \"StdEnv\"\n\t , \"StdLib\"\n\t , \"ArgEnv\"\n\t , \"Directory\"\n\t , \"Dynamics\"\n\t , \"Gast\"\n\t , \"Generics\"\n\t , \"MersenneTwister\"\n\t , \"TCPIP\"\n\t , \"clean-platform\/OS-Independent\"\n\t , \"clean-platform\/OS-Linux\"\n\t , \"clean-platform\/OS-Linux-32\"\n\t , \"clean-platform\/OS-Linux-64\"\n\t , \"clean-platform\/OS-Mac\"\n\t , \"clean-platform\/OS-Posix\"\n\t , \"clean-platform\/OS-Windows\"\n\t , \"clean-platform\/OS-Windows-32\"\n\t , \"clean-platform\/OS-Windows-64\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > builddb.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (mods, w) = findModules` cli.libs cli.root w\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop mods 'DB'.newDb cache w\n\t# f = 'DB'.saveDb db f\n\t= fclose f w\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: [(String,String)] 'DB'.TypeDB *DclCache *World -> *('DB'.TypeDB, *World)\n\tloop [] db _ w = (db,w)\n\tloop [(lib,mod):list] db cache w\n\t# (db, cache, w) = getModuleTypes mod lib cache db w\n\t= loop list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[x:c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\/\/ Libraries Library Module\nfindModules` :: ![String] !String !*World -> *(![(String,String)], !*World)\nfindModules` [] _ w = ([], w)\nfindModules` [lib:libs] root w\n#! (mods, w) = findModules lib root w\n#! (moremods, w) = findModules` libs root w\n= (removeDup (mods ++ moremods), w)\n\nfindModules :: !String !String !*World -> *(![(String,String)], !*World)\nfindModules lib root w\n#! (fps, w) = readDirectory (root +++ \"\/\" +++ lib) w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (tuple (root +++ lib)) $ map (\\s->s%(0,size s-5)) $ filter isDclModule fps\n#! (moremods, w) = findModules` (map ((+++) (lib+++\"\/\")) (filter isDirectory fps)) root w\n= (removeDup (mods ++ moremods), w)\nwhere\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String String *DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes mod lib cache db w\n# filename = lib +++ \"\/\" +++ mkdir mod +++ \".dcl\"\n# (ok,f,w) = fopen filename FReadText w\n| not ok = abort (\"Couldn't open file \" +++ filename +++ \".\\n\")\n# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n cache = {cache & hash_table=ht}\n# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" False mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n cache = {cache & hash_table=ht}\n# (ok,w) = fclose f w\n| not ok = abort (\"Couldn't close file \" +++ filename +++ \".\\n\")\n# mod = pm.mod_ident.id_name\n# db = 'DB'.putTypes (pd_typespecs mod pm.mod_defs) db\n# db = 'DB'.putInstancess (pd_instances mod pm.mod_defs) db\n# db = 'DB'.putClasses (pd_classes mod pm.mod_defs) db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = {if (c == '.') '\/' c\\\\c<-:s}\n\n\tpd_typespecs :: String [ParsedDefinition] -> [('DB'.FunctionLocation, 'DB'.ExtendedType)]\n\tpd_typespecs mod pds\n\t\t= [('DB'.FL lib mod id_name, 'DB'.ET ('T'.toType t) {te_priority=toPrio p})\n\t\t \\\\ PD_TypeSpec pos id=:{id_name} p (Yes t) funspecs <- pds]\n\twhere\n\t\ttoPrio :: Priority -> Maybe 'DB'.TE_Priority\n\t\ttoPrio (Prio LeftAssoc i) = Just $ 'DB'.LeftAssoc i\n\t\ttoPrio (Prio RightAssoc i) = Just $ 'DB'.RightAssoc i\n\t\ttoPrio (Prio NoAssoc i) = Just $ 'DB'.NoAssoc i\n\t\ttoPrio _ = Nothing\n\n\tpd_instances :: String [ParsedDefinition] -> [('DB'.Class, ['DB'.Type])]\n\tpd_instances mod pds\n\t\t= [(pi_ident.id_name, map 'T'.toType pi_types)\n\t\t \\\\ PD_Instance {pim_pi={pi_ident,pi_types}} <- pds]\n\n\tpd_classes :: String [ParsedDefinition]\n\t\t-> [('DB'.ClassLocation, ['T'.TypeVar], [('DB'.FunctionName, 'DB'.ExtendedType)])]\n\tpd_classes mod pds\n\t# pds = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) pds\n\t= map (\\(PD_Class {class_ident={id_name},class_args} pds)\n\t\t-> let typespecs = pd_typespecs mod pds\n\t\tin ('DB'.CL lib mod id_name, map 'T'.toTypeVar class_args, \n\t\t\t[(f,et) \\\\ ('DB'.FL _ _ f, et) <- typespecs])) pds\n\nunigroups :: (Type Type -> Bool) [(a,Type)] -> [([a],Type)]\nunigroups f ts = unigroups` ts []\nwhere\n\tunigroups` [] groups = groups\n\tunigroups` [(a,t):ts] [] = unigroups` ts [([a],t)]\n\tunigroups` [(a,t):ts] [(ns,ut):groups]\n\t| f t ut\t= unigroups` ts [([a:ns],ut):groups]\n\t| otherwise = unigroups` ts [(ns,ut):unigroups` [(a,t)] groups]\n\n(<+) infixr 5 :: a b -> [String] | print a & print b\n(<+) a b = print a ++ print b\n\njoin :: a [b] -> [String] | print a & print b\njoin _ [] = []\njoin a [b:[]] = print b\njoin a [b:bs] = b <+ a <+ join a bs\n\nalignl :: Int a -> [String] | print a\nalignl i s\n# s = print s\n# len = sum (map size s)\n| len >= i = s\n| otherwise = s ++ [{' ' \\\\ i <- [0..i-len]}]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","old_contents":"module builddb\n\n\/\/ Project libraries\nimport qualified TypeDB as DB\nfrom TypeDB import ::TypeExtras{..}\n\n\/\/ StdEnv\nimport StdFile, StdList, StdMisc, StdArray, StdBool, StdString, StdTuple\n\n\/\/ CleanPlatform\nimport Data.Maybe, Data.Either, Data.Error, Data.Func, Data.Tuple, Data.Functor\nfrom Text import class Text(concat), instance Text String\nimport System.Directory, System.CommandLine\n\n\/\/ CleanTypeUnifier\nimport qualified Type as T\nfrom Type import class print(print), instance print [a], instance print String\nimport CoclUtils\n\n\/\/ frontend\n\/\/import Heap, compile, parse, predef\nimport Heap\nfrom hashtable import ::HashTable, ::QualifiedIdents(NoQualifiedIdents), ::IdentClass(IC_Module), ::BoxedIdent{..}, putIdentInHashTable\nfrom predef import init_identifiers\nfrom compile import empty_cache, ::DclCache{hash_table}\nfrom general import ::Optional(..)\nfrom syntax import ::SymbolTable, ::SymbolTableEntry, ::Ident{..}, ::SymbolPtr, ::Position(NoPos), ::Module{mod_ident,mod_defs}, ::ParsedDefinition(PD_TypeSpec,PD_Instance,PD_Class), ::FunSpecials, ::Priority, ::ParsedModule, ::SymbolType, ::ParsedInstanceAndMembers{..}, ::ParsedInstance{pi_ident,pi_types}, ::Type, ::ClassDef{class_ident,class_args}, ::TypeVar\nfrom scanner import ::Priority(..), ::Assoc(..)\nfrom parse import wantModule\n\n:: CLI = {\n\thelp :: Bool,\n\tversion :: Bool,\n\troot :: String,\n\tlibs :: [String]}\n\ninstance zero CLI where\n\tzero = { version = False\n\t , help = False\n\t , root = \"\/opt\/clean\/lib\/\"\n\t , libs = [ \"StdEnv\"\n\t , \"StdLib\"\n\t , \"ArgEnv\"\n\t , \"Directory\"\n\t , \"Dynamics\"\n\t , \"Gast\"\n\t , \"Generics\"\n\t , \"MersenneTwister\"\n\t , \"TCPIP\"\n\t , \"clean-platform\/OS-Independent\"\n\t , \"clean-platform\/OS-Linux\"\n\t , \"clean-platform\/OS-Linux-32\"\n\t , \"clean-platform\/OS-Linux-64\"\n\t , \"clean-platform\/OS-Mac\"\n\t , \"clean-platform\/OS-Posix\"\n\t , \"clean-platform\/OS-Windows\"\n\t , \"clean-platform\/OS-Windows-32\"\n\t , \"clean-platform\/OS-Windows-64\"\n\t ]\n\t }\n\n\nVERSION :== \"Cloogle's builddb version 0.1\\n\"\nUSAGE :== concat [\n\tVERSION, \"\\n\",\n\t\"Usage: .\/builddb [opts] > builddb.json\\n\\n\",\n\t\"\\t-h, --help Show this help\\n\",\n\t\"\\t-r PATH Change the library root to PATH\\n\",\n\t\"\\t-l PATH Add PATH to the librarypaths relative to the root\\n\"]\n\nStart w\n# (args, w) = getCommandLine w\n# (f, w) = stdio w\n# (ok, w) = case parseCLI (tl args) of\n\t(Left e) = fclose (f <<< e) w\n\t(Right cli)\n\t| cli.help = fclose (f <<< USAGE) w\n\t| cli.version = fclose (f <<< VERSION) w\n\t# (mods, w) = findModules` cli.libs cli.root w\n\t# (st, w) = init_identifiers newHeap w\n\t# cache = empty_cache st\n\t# (db, w) = loop mods 'DB'.newDb cache w\n\t# f = 'DB'.saveDb db f\n\t= fclose f w\n| not ok = abort \"Couldn't close stdio\"\n= w\nwhere\n\tloop :: [(String,String)] 'DB'.TypeDB *DclCache *World -> *('DB'.TypeDB, *World)\n\tloop [] db _ w = (db,w)\n\tloop [(lib,mod):list] db cache w\n\t# (db, cache, w) = getModuleTypes mod lib cache db w\n\t= loop list db cache w\n\n\tparseCLI :: [String] -> Either String CLI\n\tparseCLI [] = Right zero\n\tparseCLI [x:a] = case (x,a) of\n\t\t(\"--help\", xs) = (\\c->{c & help=True}) <$> parseCLI xs\n\t\t(\"--version\", xs) = (\\c->{c & version=True}) <$> parseCLI xs\n\t\t(\"-l\", []) = Left \"'-l' requires an argument\"\n\t\t(\"-r\", []) = Left \"'-r' requires an argument\"\n\t\t(\"-r\", [x:xs]) = (\\c->{c & root=x}) <$> parseCLI xs\n\t\t(\"-l\", [x:xs]) = (\\c->{c & libs=[x:c.libs]}) <$> parseCLI xs\n\t\t(x, _) = Left $ \"Unknown option '\" +++ x +++ \"'\"\n\n\/\/ Libraries Library Module\nfindModules` :: ![String] !String !*World -> *(![(String,String)], !*World)\nfindModules` [] _ w = ([], w)\nfindModules` [lib:libs] root w\n#! (mods, w) = findModules lib root w\n#! (moremods, w) = findModules` libs root w\n= (removeDup (mods ++ moremods), w)\n\nfindModules :: !String !String !*World -> *(![(String,String)], !*World)\nfindModules lib root w\n#! (fps, w) = readDirectory (root +++ \"\/\" +++ lib) w\n| isError fps = ([], w)\n#! fps = fromOk fps\n#! mods = map (tuple (root +++ lib)) $ map (\\s->s%(0,size s-5)) $ filter isDclModule fps\n#! (moremods, w) = findModules` (map ((+++) (lib+++\"\/\")) (filter isDirectory fps)) root w\n= (removeDup (mods ++ moremods), w)\nwhere\n\tisDclModule :: String -> Bool\n\tisDclModule s = s % (size s - 4, size s - 1) == \".dcl\"\n\n\tisDirectory :: String -> Bool\n\tisDirectory s = not $ isMember '.' $ fromString s\n\ngetModuleTypes :: String String *DclCache 'DB'.TypeDB *World -> *('DB'.TypeDB, *DclCache, *World)\ngetModuleTypes mod lib cache db w\n# filename = lib +++ \"\/\" +++ mkdir mod +++ \".dcl\"\n# (ok,f,w) = fopen filename FReadText w\n| not ok = abort (\"Couldn't open file \" +++ filename +++ \".\\n\")\n# (mod_id, ht) = putIdentInHashTable mod (IC_Module NoQualifiedIdents) cache.hash_table\n cache = {cache & hash_table=ht}\n# ((b1,b2,pm,ht,f),w) = accFiles (wantModule` f \"\" False mod_id.boxed_ident NoPos True cache.hash_table stderr) w\n cache = {cache & hash_table=ht}\n# (ok,w) = fclose f w\n| not ok = abort (\"Couldn't close file \" +++ filename +++ \".\\n\")\n# mod = pm.mod_ident.id_name\n# db = 'DB'.putTypes (pd_typespecs mod pm.mod_defs) db\n# db = 'DB'.putInstancess (pd_instances mod pm.mod_defs) db\n# db = 'DB'.putClasses (pd_classes mod pm.mod_defs) db\n= (db,cache,w)\nwhere\n\tmkdir :: String -> String\n\tmkdir s = {if (c == '.') '\/' c\\\\c<-:s}\n\n\tpd_typespecs :: String [ParsedDefinition] -> [('DB'.FunctionLocation, 'DB'.ExtendedType)]\n\tpd_typespecs mod pds\n\t# pds = filter (\\pd->case pd of (PD_TypeSpec _ _ _ _ _)=True; _=False) pds\n\t# sts = map (\\(PD_TypeSpec pos id p st funspecs) -> ('DB'.FL lib mod id.id_name,st,p)) pds\n\t# sts = [(fl, 'DB'.ET ('T'.toType x) {te_priority=toPrio p}) \\\\ (fl,Yes x,p) <- sts]\n\t= sts\n\twhere\n\t\ttoPrio :: Priority -> Maybe 'DB'.TE_Priority\n\t\ttoPrio (Prio LeftAssoc i) = Just $ 'DB'.LeftAssoc i\n\t\ttoPrio (Prio RightAssoc i) = Just $ 'DB'.RightAssoc i\n\t\ttoPrio (Prio NoAssoc i) = Just $ 'DB'.NoAssoc i\n\t\ttoPrio _ = Nothing\n\n\tpd_instances :: String [ParsedDefinition] -> [('DB'.Class, ['DB'.Type])]\n\tpd_instances mod pds\n\t# pds = filter (\\pd->case pd of (PD_Instance _)=True; _=False) pds\n\t= map (\\(PD_Instance {pim_pi={pi_ident,pi_types}})\n\t\t-> (pi_ident.id_name, map 'T'.toType pi_types)) pds\n\n\tpd_classes :: String [ParsedDefinition]\n\t\t-> [('DB'.ClassLocation, ['T'.TypeVar], [('DB'.FunctionName, 'DB'.ExtendedType)])]\n\tpd_classes mod pds\n\t# pds = filter (\\pd->case pd of (PD_Class _ _)=True; _=False) pds\n\t= map (\\(PD_Class {class_ident={id_name},class_args} pds)\n\t\t-> let typespecs = pd_typespecs mod pds\n\t\tin ('DB'.CL lib mod id_name, map 'T'.toTypeVar class_args, \n\t\t\t[(f,et) \\\\ ('DB'.FL _ _ f, et) <- typespecs])) pds\n\nunigroups :: (Type Type -> Bool) [(a,Type)] -> [([a],Type)]\nunigroups f ts = unigroups` ts []\nwhere\n\tunigroups` [] groups = groups\n\tunigroups` [(a,t):ts] [] = unigroups` ts [([a],t)]\n\tunigroups` [(a,t):ts] [(ns,ut):groups]\n\t| f t ut\t= unigroups` ts [([a:ns],ut):groups]\n\t| otherwise = unigroups` ts [(ns,ut):unigroups` [(a,t)] groups]\n\n(<+) infixr 5 :: a b -> [String] | print a & print b\n(<+) a b = print a ++ print b\n\njoin :: a [b] -> [String] | print a & print b\njoin _ [] = []\njoin a [b:[]] = print b\njoin a [b:bs] = b <+ a <+ join a bs\n\nalignl :: Int a -> [String] | print a\nalignl i s\n# s = print s\n# len = sum (map size s)\n| len >= i = s\n| otherwise = s ++ [{' ' \\\\ i <- [0..i-len]}]\n\nwantModule` :: !*File !{#Char} !Bool !Ident !Position !Bool !*HashTable !*File !*Files\n\t-> ((!Bool,!Bool,!ParsedModule, !*HashTable, !*File), !*Files)\nwantModule` f s b1 i p b2 ht io fs\n# (b1,b2,pm,ht,f,fs) = wantModule f s b1 i p b2 ht io fs\n= ((b1,b2,pm,ht,f),fs)\n","returncode":0,"stderr":"","license":"mit","lang":"Clean"} {"commit":"ac2c242ce594f3372b0ba05a90c248269dc187fd","subject":"Minor improvement","message":"Minor improvement\n","repos":"camilstaps\/iClean,camilstaps\/iClean","old_file":"iclean.icl","new_file":"iclean.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/iClean.git\/'\n","license":"mit","lang":"Clean"} {"commit":"470ba44a86690db4ce8205818745a7d1d2f23e21","subject":"Fix LogicTest","message":"Fix LogicTest\n","repos":"camilstaps\/CleanLogic,camilstaps\/CleanLogic","old_file":"LogicTest.icl","new_file":"LogicTest.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/CleanLogic.git\/'\n","license":"mit","lang":"Clean"} {"commit":"c7f5716d83815355542a3b4da7ceb6a8655c1311","subject":"@.@. fix","message":"@.@. fix\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanCoord.icl","new_file":"code\/SokobanCoord.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"fatal: unable to access 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/': The requested URL returned error: 403\n","license":"mit","lang":"Clean"} {"commit":"6a87656853682fdfccd84353fa7b9da182994aff","subject":"coord generator minor fixes","message":"coord generator minor fixes\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanCoord.icl","new_file":"code\/SokobanCoord.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"8befabf960165fe8c3ce6b1dfd280bf6d7500766","subject":"Made module object so the files stay small","message":"Made module object so the files stay small\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanObjectwise.icl","new_file":"code\/SokobanObjectwise.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"74c4e8e02dc1189eac521552566678914631737f","subject":"Use gPrint instead of genShow for printing results","message":"Use gPrint instead of genShow for printing results\n","repos":"camilstaps\/iClean,camilstaps\/iClean","old_file":"iclean.icl","new_file":"iclean.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/iClean.git\/'\n","license":"mit","lang":"Clean"} {"commit":"2f4b63dc80a953da51685a5ed584c89500ed17f1","subject":"Added show_result option","message":"Added show_result option\n","repos":"camilstaps\/iClean,camilstaps\/iClean","old_file":"iclean.icl","new_file":"iclean.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/iClean.git\/'\n","license":"mit","lang":"Clean"} {"commit":"667e32825c62ca48514afd0b29e1d5ba9d924978","subject":"Bugfixes in show functions (parentheses)","message":"Bugfixes in show functions (parentheses)\n","repos":"camilstaps\/CleanLogic,camilstaps\/CleanLogic","old_file":"Logic.icl","new_file":"Logic.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/CleanLogic.git\/'\n","license":"mit","lang":"Clean"} {"commit":"fcf8e87a48de34945743d764ee17a1c8dbb83fbb","subject":"Bugfix logicparser","message":"Bugfix logicparser\n","repos":"camilstaps\/CleanLogic,camilstaps\/CleanLogic","old_file":"LogicParser.icl","new_file":"LogicParser.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/CleanLogic.git\/'\n","license":"mit","lang":"Clean"} {"commit":"ac799d3f661e5440845954ec72b80a98ca26c511","subject":"coord solution (unfinished)","message":"coord solution (unfinished)\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanCoord.icl","new_file":"code\/SokobanCoord.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"dcffc3bd15617a7e965282dcbd9e632d512aeb50","subject":"- add xhtml","message":"- add xhtml\n","repos":"grimneko\/iroffer-modDinoex,grimneko\/iroffer-modDinoex,grimneko\/iroffer-modDinoex","old_file":"dtd\/xml1.dcl","new_file":"dtd\/xml1.dcl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/grimneko\/iroffer-modDinoex.git\/'\n","license":"lgpl-2.1","lang":"Clean"} {"commit":"b54c926d7f8fd59ad45b1be8c74fc3e60cec1ad7","subject":"Change :import to import","message":"Change :import to import\n","repos":"camilstaps\/iClean,camilstaps\/iClean","old_file":"iclean.icl","new_file":"iclean.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/iClean.git\/'\n","license":"mit","lang":"Clean"} {"commit":"b0e2a7a87a40d36b3d1afea00ed01db7da93d544","subject":"Cleanup, removed warnings, newline at end session","message":"Cleanup, removed warnings, newline at end session\n","repos":"camilstaps\/iClean,camilstaps\/iClean","old_file":"iclean.icl","new_file":"iclean.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/iClean.git\/'\n","license":"mit","lang":"Clean"} {"commit":"ea99b6c1a5c786744df79413b4ea0ec830e67be9","subject":"come cleaning","message":"come cleaning\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanCoord.icl","new_file":"code\/SokobanCoord.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"c2f18e81f24962057945dc3fbf48d00a0f03537c","subject":"works, tested with 2000 and 642","message":"works, tested with 2000 and 642\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanObjectwise.icl","new_file":"code\/SokobanObjectwise.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"20f674ab92301fee4066718ca16e5d4edc08ffcb","subject":"- add xhtml","message":"- add xhtml\n","repos":"grimneko\/iroffer-modDinoex,grimneko\/iroffer-modDinoex,grimneko\/iroffer-modDinoex","old_file":"dtd\/xml1.dcl","new_file":"dtd\/xml1.dcl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/grimneko\/iroffer-modDinoex.git\/'\n","license":"lgpl-2.1","lang":"Clean"} {"commit":"bd74997680c2ff4a2af3445050f5ed7baa041e04","subject":"initials generation added","message":"initials generation added\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanCoord.icl","new_file":"code\/SokobanCoord.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"ffbe00b0e61738443c25463fd26c24a71173d4c3","subject":"small clean-up","message":"small clean-up\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanCoord.icl","new_file":"code\/SokobanCoord.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"a3c32c724d37996ac7e1b8f1557b6fb55963328d","subject":"Add :undef","message":"Add :undef\n","repos":"camilstaps\/iClean,camilstaps\/iClean","old_file":"iclean.icl","new_file":"iclean.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/iClean.git\/'\n","license":"mit","lang":"Clean"} {"commit":"4211e0aeed639a9eb14488d456cd95bdffc16118","subject":"added stub for boxonbox thing","message":"added stub for boxonbox thing\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanObjectwise.icl","new_file":"code\/SokobanObjectwise.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"1df8158b127c3888d1ab10db0e6c05da2c795e1c","subject":"added agent","message":"added agent\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/Sokoban.dcl","new_file":"code\/Sokoban.dcl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"6530eaf3b0311d83845c7aceac3514a60436235b","subject":"Fixing last commit; parentheses chained implications","message":"Fixing last commit; parentheses chained implications\n","repos":"camilstaps\/CleanLogic,camilstaps\/CleanLogic","old_file":"Logic.icl","new_file":"Logic.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/CleanLogic.git\/'\n","license":"mit","lang":"Clean"} {"commit":"feace407c0e94ba940f7e1ffb5706d78ddb71760","subject":"annotations added in the code","message":"annotations added in the code\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanObjectwise.icl","new_file":"code\/SokobanObjectwise.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"37faa690fedaf0f7ce861c97f78d23bbba3fee07","subject":"generation with model stub (still prototyping)","message":"generation with model stub (still prototyping)\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanCoord.icl","new_file":"code\/SokobanCoord.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"fatal: unable to access 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/': The requested URL returned error: 403\n","license":"mit","lang":"Clean"} {"commit":"9754f5cfb7a38d480ecf72dc87d4c67cd774c9d7","subject":"interface for sokoban","message":"interface for sokoban\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/Sokoban.dcl","new_file":"code\/Sokoban.dcl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"fce8f94ed6880b60ee021e5a56cdd815fa3b0fd2","subject":"some cleanup","message":"some cleanup\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanCoord.icl","new_file":"code\/SokobanCoord.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"} {"commit":"926318dc6938a55df4658f8af46b069352ccb458","subject":"Fixed issue where truth tables had too many options","message":"Fixed issue where truth tables had too many options\n","repos":"camilstaps\/CleanLogic,camilstaps\/CleanLogic","old_file":"Logic.icl","new_file":"Logic.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/CleanLogic.git\/'\n","license":"mit","lang":"Clean"} {"commit":"5cb98e56427777858b429a551f2a2671d68a2c51","subject":"Resolve #2: enable\/disable showing types","message":"Resolve #2: enable\/disable showing types\n","repos":"camilstaps\/iClean,camilstaps\/iClean","old_file":"iclean.icl","new_file":"iclean.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/iClean.git\/'\n","license":"mit","lang":"Clean"} {"commit":"4cfd4cbbed7e93c092a44285ae519d08b587efc4","subject":"Cleanup","message":"Cleanup\n","repos":"camilstaps\/CleanLogic,camilstaps\/CleanLogic","old_file":"Logic.icl","new_file":"Logic.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/camilstaps\/CleanLogic.git\/'\n","license":"mit","lang":"Clean"} {"commit":"a7a9fa5ded371c89459ba6872290774488ec7c3d","subject":"works!","message":"works!\n","repos":"dopefishh\/mc1516pa,dopefishh\/mc1516pa","old_file":"code\/SokobanObjectwise.icl","new_file":"code\/SokobanObjectwise.icl","new_contents":"","old_contents":"","returncode":128,"stderr":"remote: Support for password authentication was removed on August 13, 2021.\nremote: Please see https:\/\/docs.github.com\/en\/get-started\/getting-started-with-git\/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.\nfatal: Authentication failed for 'https:\/\/github.com\/dopefishh\/mc1516pa.git\/'\n","license":"mit","lang":"Clean"}