Skip to content

Instantly share code, notes, and snippets.

Avatar
🐴
everything happens so much oh no

Quil robotlolita

🐴
everything happens so much oh no
View GitHub Profile
@robotlolita
robotlolita / map.st
Last active Aug 28, 2015 — forked from joepie91/map.js
Bluebird map + bhttp
View map.st
(* Assume bhttp-get is available here somehow *)
let HTTP = {
def get: url
(* This would actually need to be imported properly. Yeah, FFI sucks, but oh well... *)
Task from-promise: (FFI invoke: bhttp-get in-context: unit with-arguments: [FFI export: url])
}
do {
response <- HTTP get: "http://somesite.com/all-the-urls.txt";
View foo.hs
data Maybe a = Nothing | Just: a
Nothing map: transform => Nothing
(Just: a) map: transform => Just: a transform
type Named a = {a | name: String }
{- { name: String, age: Int } -}
@robotlolita
robotlolita / pressed.elm
Created Feb 11, 2014
Shows different text than what was pressed
View pressed.elm
import Char
import Keyboard
import String
toString char = String.cons (Char.fromCode char) ""
typed text = plainText "You typed: " `beside` asText text
transformed text = plainText "I'll show you: " `beside` (asText . String.reverse <| text)
@robotlolita
robotlolita / web.java
Last active Aug 29, 2015
Java web vs Phemme
View web.java
package something;
import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.annotation.WebServlet;
@WebServlet("/")
@robotlolita
robotlolita / index.js
Last active Aug 29, 2015
Monadic wrapper for Express API
View index.js
var express = require('express')
var app = require('./wrapper')(express())
require('./routes')(app)
app.listen(8080)
console.log('Listening on http://localhost:8080')
@robotlolita
robotlolita / sum-digits.hm.hs
Last active Aug 29, 2015
sum digits in Harmonia
View sum-digits.hm.hs
module Fib using: Platform where
open Platform Prelude expose [+, parse, as-string, ~]
open Platform List expose [zip:using:, map:, take:, filter:, sum]
open Platform IO expose [read-line, print]
-- Typing things is currently cumbersome, but the type inference algorithm should catch 90% of this
let (Num a) => String -> a ::
x as-number = x parse
@robotlolita
robotlolita / 0-instructions.md
Last active Aug 29, 2015
BECAUSE TYPE SYSTEMS ARE SUPPOSED TO RUN COMPUTATIONS!!1!1!
View 0-instructions.md

Write a program in your favourite programming language to compute the sum of the first N even numbers in the Fibonacci sequence, then display the sum of its digits.

E.g.: Where N = 5, the answer is 17, since:

  1. The Fibonacci sequence is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ...;
  2. The first 5 even numbers are 0, 2, 8, 34, and 144;
  3. The sum of these numbers is 188;
  4. The sum of the digits of this answer is 17 (1 + 8 + 8).
View Language War.cpp
/*
[DESAFIO / LANGUAGE WAR] Implemente um programa na sua linguagem favorita onde o usuário digita um número x, e o programa calcula o somatório dos x primeiros números pares da sequência fibonacci, e imprime a soma dos algarismos desse número.
Por exemplo, quando x = 5, a resposta é 17, pois:
1. A sequência fibonacci é 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,...
2. Os 5 primeiros números pares são 0, 2, 8 e 34, 144.
3. O somatório disso é 188.
4. Somando os algarismos, 1+8+8 = 17
@robotlolita
robotlolita / expression-problem.hs
Last active Aug 29, 2015
Solving the expression problem in Harmonia (with structural typing through row-polymorphism and multi-methods)
View expression-problem.hs
module Expression using: Platform where
open Platform Math expose [sqrt, +, -, *, /, π]
open Platform IO expose [print]
type Circle = { radius :: Double }
type Square = { side :: Double }
let { _ | side: s } area = s * s -- inferred type: { a | side :: Double } -> Double
let { _ | radius: r } area = π * r * r -- inferred type: { a | radius :: Double } -> Double
View applicative.js
// :: String -> String
function concat(a){ return function(b){
return a + b
}}
// :: (a -> b -> c) -> (b -> a -> c)
function flip(f){ return function(a){ return function(b) {
return f(b)(a)
}}}