4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Advent of JustinAdvent Calendar 2018

Day 3

AOJ day 3: Tanghulu

Last updated at Posted at 2018-12-02

While most people associate PureScript with row types, capabilites of Symbols has grown with each release of PureScript, to the point that now we have a Symbol Cons type class now in PureScript 0.12.x to split a known symbol to its head and tail. These Symbol type classes let us apply dependently-typed techniques using statically defined type-level strings.

"We don't need Peano Numbers in PureScript"

Of course, any demonstration of dependently-typed techniques would not be complete without some obnoxious sized list demo, so I wrote about one using the type class Prim.Symbol.Append:

https://qiita.com/kimagure/items/522fa4dd4abdcc313c8e

The gist of this post is that when we look at the definition of the type class and its functional dependencies, we can treat this like addition of two numbers to a sum:

class Append (left :: Symbol) (right :: Symbol) (appended :: Symbol)
  | left right -> appended
  , right appended -> left
  , appended left -> right

That is,

a <> b == c
  | a b -> c
  , b c -> a
  , a c -> b

And so with "." <> ".." == "..." and the fundeps above, we can get to work making arithmetic work for symbols of period ".". Amazing!

We'll get more into how to use Symbol for more fun things in future posts.

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?