mudasobwa

mudasobwa

Creator of Cure

I know I put the cart before the horse, but AI providers started this race, not me.

Welcome Typle, the library that leverages a modern Elixir type system to discover types given the bunch of Elixir code.

The real application is my credo add-ons. In our team there are people who sometimes get lazy and use Access everywhere like: container[:key] no matter what container is. Also there are assistants who always use Access, because container.key is less fancy, or who knows why. I personally find this quite disturbing. Let alone Access is slower, it absolutely does not belong here.

So I started to implement a credo check for that, and I realized I should issue a warning if and only if the container is a map (and a key is an atom literal, but that’s a no-brainer.)

That’s how Typle was born. It’s just a baby-lib, but it might be already quite useful for those linting their code.

iex|🌢|1 ▶ {:ok, type} = Typle.Inference.infer_file("test/support/sample_module.ex")
{:ok,
 %{
   exprs: %{
     {6, 11} => "a",
     {6, 14} => "b",
     {7, 5} => "a",
     {7, 7} => ":erlang.+(a, b)",
     {7, 9} => "b",
     {10, 13} => "name",
     {11, 0} => "<<\"Hello, \", name::binary>>",
     {14, 19} => "input",
     {15, 5} => "case Integer.parse(input) do\n  {num, _rest} -> {:ok, num}\n  :error -> {:error, :invalid}\nend",
     {15, 17} => "Integer.parse(input)",
     {15, 24} => "input",
     {16, 8} => "num",
     {16, 13} => "_rest",
     {16, 29} => "num",
     {21, 22} => "x",
     {21, 30} => "x",
     {22, 16} => "x",
     {22, 24} => "x"
   },
   types: %{
     {6, 11} => #Typle.Type<dynamic()>,
     {6, 14} => #Typle.Type<dynamic()>,
     {7, 5} => #Typle.Type<integer()>,
     {7, 7} => #Typle.Type<dynamic(float() or integer())>,
     {7, 9} => #Typle.Type<integer()>,
     {10, 13} => #Typle.Type<dynamic()>,
     {11, 0} => #Typle.Type<binary()>,
     {14, 19} => #Typle.Type<dynamic()>,
     {15, 5} => #Typle.Type<{:error, :invalid} or {:ok, dynamic(integer())}>,
     {15, 17} => #Typle.Type<dynamic(:error or {integer(), binary()})>,
     {15, 24} => #Typle.Type<dynamic()>,
     {16, 8} => #Typle.Type<dynamic(integer())>,
     {16, 13} => #Typle.Type<dynamic(binary())>,
     {16, 29} => #Typle.Type<dynamic(integer())>,
     ...
   }
 }}

mix tasks included.

Enjoy!

https://github.com/Oeditus/typle

First 2 of 2 Posts Switch mode

ycastor

ycastor

Ooooo, this is nice! Everything you build is gold. This will be useful for a lean-of-elixir toy-project i’m playing with.

mudasobwa

mudasobwa OP

Creator of Cure

:person_bowing:

— All posts loaded —

Where Next? Top

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 15136 120
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 11030 135
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
woylie
Phoenix components for pagination, sortable tables and filter forms with Flop and (optionally) Ecto. pagination cursor pagination sorta...
New
kip
Please say hi to a new lib, Astro that aims to deliver easy-to-consume astronomy calculations of practical use. For now it only calculat...
New

Other Trending Topics Top

akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New

We're in Beta

About us Mission Statement