Skip to content

Instantly share code, notes, and snippets.

View danidiaz's full-sized avatar

Daniel Díaz Carrete danidiaz

View GitHub Profile
Prelude M R> :set -XTypeApplications -XDataKinds -XFlexibleContexts -XAllowAmbiguousTypes
import qualified Data.RBR as R -- from "red-black-record"
Prelude M R> :{
Prelude M R| let r = R.insertI @"a" (3::Int)
Prelude M R| . R.insertI @"b" False
Prelude M R| . R.insertI @"c" 'c'
Prelude M R| $ R.unit
// https://www.golang-book.com/books/intro
package main
import ("fmt"
"reflect")
func main() {
fmt.Printf("hello, world\n")
//var foo string = "foooo"
var x [5]int
@danidiaz
danidiaz / playground.ql
Last active January 19, 2020 23:47
QL playground
//
from string s
where s = "hello".charAt(_)
select s
//
predicate isCountry(string country) {
country = "Germany"
or
country = "Belgium"
@danidiaz
danidiaz / Pipelines.hs
Last active January 17, 2020 16:41
A GADT for chains of functions, that remembers the types of the intermediate steps using a type-level list. https://www.reddit.com/r/haskell/comments/ei5kek/monthly_hask_anything_january_2020/fcpeppz/
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
module Pipy where
import Data.Kind (Type)
import GHC.TypeLits
import Data.Char (isAlpha)
-- GADT containing a chain of functions, and which remembers the types of each internal step.
data Pipeline (start :: Type) (middle :: [Type]) (end :: Type) where
@danidiaz
danidiaz / JSONUsingTaggedFields.hs
Last active November 14, 2019 21:41
from and to JSON using tagged fields
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
-- this file requires aeson and generics-sop
@danidiaz
danidiaz / Foo.rb
Created October 25, 2019 06:23
Minimal Ruby program for experimenting with truffle-ruby tooling
class Foo
def initialize()
@val = 0
end
def go_up()
@val+=1
end
def go_down()
@val-=1
end
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Main where
import GHC.OverloadedLabels
import GHC.Records
@danidiaz
danidiaz / CustomGraalCEDockerfile
Last active September 16, 2019 21:43
customized Graal CE Dockerfile for Truffle experiments
FROM oracle/graalvm-ce
WORKDIR /truffle-sandbox
RUN yum-config-manager --save --setopt=ol7_developer_EPEL.skip_if_unavailable=true && \
yum install -y iputils && \
yum install -y iproute && \
yum install -y xeyes && \
yum install -y git && \
yum install -y maven && \
yum install -y vim && \
gu install native-image && \
@danidiaz
danidiaz / CR001RotatingColorfulSquares.hs
Last active July 3, 2019 19:16
Codeworld-Reflex experiments
{-# LANGUAGE BlockArguments #-}
import CodeWorld.Reflex
import Reflex
-- Move mouse to rotate squares.
-- Click to add squares.
positions :: [(Color,(Double,Double))]
positions = zip assortedColors [(0,0),(2,2),(-2,2),(-2,-2),(2,-2)]