mudasobwa

mudasobwa

Creator of Cure

Typle - Expression-level type query library for Elixir 1.20+

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

Most Liked

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.

Last Post!

mudasobwa

mudasobwa

Creator of Cure

:person_bowing:

Where Next?

Popular in Announcing Top

zorbash
I created Kitto a framework for dashboards inspired by Dashing. The distributed characteristics of Elixir and the low memory footprint...
New
jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
tmbb
I’ve decided to create this topic to discuss optimization possibilities for something like Phoenix LiveView. I’ve created this topic unde...
144 10789 141
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement