Skip to content

Instantly share code, notes, and snippets.

Avatar

Artyom Shalkhakov ashalkhakov

View GitHub Profile
@ashalkhakov
ashalkhakov / dynamic.dats
Created Oct 26, 2012
Dynamic typing in a statically typed programming language
View dynamic.dats
// compile with atscc, compiler for ATS, an ML dialect
// see <www.ats-lang.org>
staload _ = "prelude/DATS/list.dats"
staload _ = "prelude/DATS/string.dats"
// the type of dynamic terms
// NOTE: using an abstract type here would be true
// to the spirit of dynamically typed languages
datatype DT =
@ashalkhakov
ashalkhakov / gist:7526578
Last active Jul 10, 2019
Mapping DCIL to D4. Added more constraints. Well, only those that my ORM model needs, at the moment. Added support for clustered and sparse keys.
View gist:7526578
<?xml version="1.0" encoding="utf-8"?>
<!-- Author: Artyom Shalkhakov (artyom.shalkhakov@gmail.com)
License: BSD v3
I've used bits and pieces of other transforms bundled
with NORMA for reference, so I'm not the sole author
of this.
-->
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
@ashalkhakov
ashalkhakov / monads.dats
Created Dec 31, 2014
Encoding monads in ATS2 with function templates
View monads.dats
(* ****** ****** *)
// Monads in ATS2 using templates
#include
"share/atspre_define.hats"
(* ****** ****** *)
// the interface
abst@ype M (t@ype)
@ashalkhakov
ashalkhakov / template-view-eq.dats
Last active Aug 29, 2015
View equalities in templates
View template-view-eq.dats
#include
"share/atspre_staload.hats"
staload UN = "prelude/SATS/unsafe.sats"
#define N 5
extern
fun{env:vt@ype}
loop$fwork (natLt(N), &(env) >> _): void
View TupleTest.cs
// License: BSD 3-clause
// Author: Artyom Shalkhakov
// Date: Sep 22, 2015
//
// About: this is a POC of n-tuples and row types implemented
// using Reflection.Emit. The mutation interface (get/set methods)
// involves no boxing, but the caller has to supply the type parameter
// that matches the type of the value at the given position. Position
// is resolved using a jump table (TODO: does it translate to threaded
// code?).
@ashalkhakov
ashalkhakov / unbalacend-parens-js
Last active Apr 6, 2016
Question on unbalanced parentheses matching in a given string
View unbalacend-parens-js
(*
** Hello, world!
**
** Q: how to extract substring of input string ending at the first unclosed parens?
** ex. sldfkjsf(sldfkj)lskdjff(sdfsdf) -- this is balanced, return as-is
** ex. (sldfkj(sdfsdf(sdfsdf(sdfsdf)sdf)sdf)sdfsdf -- this is NOT balanced, first paren is unclosed (result should be empty)
** ex. esdfd((esdf)(esdf -- first paren is unclosed, should give esdfd
** A: see below
*)
View tcheck-assignment.dats
(*
** Hello, world!
** Q: what's a good way to *not* mix up = and == operators in a conditional?
** A: a good way is via typed programming
*)
(* ****** ****** *)
#include
"share/atspre_define.hats"
View gctest.dats
(*
* to compile:
*
* $ patscc -DATS_MEMALLOC_LIBC gctest.dats
*
* NOTE: no GC here
*)
#include
"share/atspre_staload.hats"
@ashalkhakov
ashalkhakov / msys2-build-ats2.sh
Last active Apr 3, 2019
Installing ATS2 on MSYS2
View msys2-build-ats2.sh
#!/usr/bin/env sh
######
#
# A shell script for
# installing ATS2 + ATS2-contrib
#
######
#
# Author: Artyom Shalkhakov
View stacked-union.dats
//
// A simple example of C-union
//
(* ****** ****** *)
//
// Author: Hongwei Xi
// Authoremail: gmhwxiATgmailDOTcom
// Start time: November, 2013
//
(* ****** ****** *)