{"id":18324711,"url":"https://github.com/tchoutri/mytrie","last_synced_at":"2025-10-11T19:39:08.653Z","repository":{"id":118115789,"uuid":"323466693","full_name":"tchoutri/mytrie","owner":"tchoutri","description":"My naïve Trie implementation","archived":false,"fork":false,"pushed_at":"2020-12-22T10:29:03.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-11T19:39:07.435Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tchoutri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-21T22:57:14.000Z","updated_at":"2021-01-09T10:05:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"4c46eb4c-e90c-45d6-a338-c2d4ee8e122f","html_url":"https://github.com/tchoutri/mytrie","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tchoutri/mytrie","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchoutri%2Fmytrie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchoutri%2Fmytrie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchoutri%2Fmytrie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchoutri%2Fmytrie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tchoutri","download_url":"https://codeload.github.com/tchoutri/mytrie/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tchoutri%2Fmytrie/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279008425,"owners_count":26084460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T18:35:36.309Z","updated_at":"2025-10-11T19:39:08.622Z","avatar_url":"https://github.com/tchoutri.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A naïve Trie implementation in Haskell\n\nMany other Haskell implementations of Tries have the structure of the datatype as such:\n\n```Haskell\ndata Trie = Bottom | Internal (HashMap Char Trie)\n```\n\nIn this implementation, the `Bottom` constructor represents the end of a path.\nOther languages like Python may represent such a thing by using a special character like '\\*' pointing to a null value.\n\nFor instance, consider the `member` function:\n\n```haskell\nmember :: Text -\u003e Trie -\u003e Bool\nmember text = go (T.head text) (T.tail text) -- (1)\n  where\n    go :: Char -\u003e Text -\u003e Trie -\u003e Bool\n    go x xs (Internal  hm) | T.null xs =     -- (2)\n      case HM.lookup x hm of\n        Nothing -\u003e False\n        Just _  -\u003e True\n    go x xs (Internal  hm) =                 -- (3)\n      let newHead = T.head xs\n          newTail = T.tail xs\n       in Just True == (go newHead newTail \u003c$\u003e HM.lookup x hm)\n       --    ^____ (3c)     ^____ (3b)            ^___ (3a)\n    go _ _ Bottom = False                    -- (4)\n```\n\nIn (1), we delegate the recursion to a helper function called `go`, by explicitly\npassing the head and tail of the text.  \n(2) shows the case where the tail of the text (`xs`) is empty. This is the moment where\nwe operate on the last element of the string of text, `x`. The final lookup is\nperformed to see if the last letter of the string is here, and we return a Boolean\naccordingly.\n\nFinally, (3) shows the recursive case.  \nIn (3a), we perform a lookup in the hashmap to determine if the character `x` we\nare currently checking is present. If it is here, it will return a `Just subTrie`\nthat the `go newHead newTail` partially applied function will use as its last\nargument, and recurse. Otherwise, `Nothing` is returned.\n\nThe expression in parenthesis that contains (3b) and (3a) has type\n`Maybe Bool`. If it returns `Nothing`, it means that a lookup in the body of the \nexpression (3a) yielded no value. If it returned `Just False`, it means that we have\narrived at the end of the text we are searching and its last letter is not present\nat the current node. If we get `Just True`, it means that the word is entirely\ncontained whithin the Trie.\n\nAnd thus, (3c) is the final comparison between what we expect to be a happy result,\n`Just True`, and the result of said comparison is the Boolean that we get at the end.\n\nFinally, (4) indicates the moment where we stumble on a too-short word path.  \nThe word we are looking for is not fully inserted in the Trie.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftchoutri%2Fmytrie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftchoutri%2Fmytrie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftchoutri%2Fmytrie/lists"}