Skip to content

Instantly share code, notes, and snippets.

View agocorona's full-sized avatar
💭
Status at .... https://gitter.im/Transient-Transient-Universe-HPlay/Lobby

Alberto agocorona

💭
Status at .... https://gitter.im/Transient-Transient-Universe-HPlay/Lobby
View GitHub Profile

Services are a standard feature of transient. a service is a transient program with a diferent codebase than the one of the calling program. the services are initiated stand alone or by the monitor service. Although they are transient haskell programs, they can execute internally wathever :they can do FFI or execute a shell. They can also be packaged into docker images.

monitorService:

-is an executable included in transient -it should run in each node of the cloud:

 monitorService -p start/thishost/3000 # first node 
@agocorona
agocorona / ATM.hs
Last active January 5, 2024 02:42
Software for an ATM (a machine that dispenses cash or performs other banking services when an account holder inserts a bank card) . It includes server and Web program
#!/usr/bin/env execthirdlinedocker.sh
-- mkdir -p ./static && ghcjs -DDEBUG ${1} -o static/out && echo ${1} && runghc -DDEBUG ${1} ${2} ${3}
{-
Programmed following the requirements of a canonical Java project:
http://www.math-cs.gordon.edu/courses/cs211/ATMExample/
It demonstates that it is possible to program clearly at the level of the requirements so that the author of the requirements
@agocorona
agocorona / erlang-transient.md
Last active March 3, 2019 18:59
Erlang versus transient distributed computing

I have been watching this interesting presentation of distributed computing in Erlang-elixir: https://www.youtube.com/watch?v=AiN4r8E9qKg

I want to mention the remarkable points and compare them with the transient way of distributed computing:

min 1:30 It defines a cookie as a command-line parameter. It is a good idea. Connections would be required to send the same cookie.

min 3:00 Erlang nodes connect all nodes with all by default and maintain a heartbeat between then, probably because the communication protocol is low level in order to be very fast. It uses UDP probably. Transient connect only on demand and a node may route request to other destination nodes. It is made for weakly coupled internet nodes rather than for a closed coupled local area network. For this reason transient uses TCP sockets and websockets. A node behind a firewall can be accessed using the HTTP port as long as websockets are enabled. Once connected the remote node can address nodes internal to the firewall trough the gateway

@agocorona
agocorona / runpatterh.md
Created March 7, 2019 18:00
Run pattern considered harmful

A lot of problems in haskell development is related with the problem of chaining effects. How do I insert an effect in a chain of computations?

Since the chain operation is bind, and has this signature:

  (>>=) :: m a -> (a -> m b) -> m b

then the two operands: the result of the chain and the rest of the chain should be in the same monad, so they should have the same effects.

To overcome this problem the monad transformer and the free monad use the "runXXX" and the lift pattern with XXX being the effect desired can run for some time:

-- first attempt (not compiled) of an example simulation of petri net https://twitter.com/semanticbeeng/status/1120662696985268225
-- assume that the input is stored by a process `receive` not detailed here which store the entries in two transactional variables
-- read from two typed channels A and B
-- return three responses of type C
import Control.Concurrent.STM.TVar
import Transient.Base
  • Do NOT use loops. Loops destroy composition. Use streaming/ non determinism (multithreaded or not):
forM [1..10]  $ \i -> ...   use:   i <- threads 0  $ choose [1..10]    
                                   -- run in the current thread
-- like for i = 1 to 10... 
  • Do NOT use callbacks. De-invert callbacks with react:
onCallback wathever mycallback    use:     event <- react (onCallback wathever) (return())         
@agocorona
agocorona / Bench.hs
Created August 31, 2019 11:17
Benchmark for the transient monad compared with others
--Based on https://gist.github.com/gelisam/be8ff8004cd701a084b6d64204a28bb6
{-# LANGUAGE DataKinds, DeriveFunctor, FlexibleContexts, GADTs, LambdaCase, RankNTypes, ScopedTypeVariables, TypeApplications, TypeOperators #-}
module Main (main) where
import qualified TransientCont as T -- this file: https://gist.github.com/agocorona/2c9149c4d2035f21952fc1d1691b7bde
import Criterion (bench, bgroup, nf,whnfIO)
import Criterion.Main (defaultMain)
@agocorona
agocorona / resources.md
Last active April 14, 2021 22:10
Asynchronous exceptions and de-inverted management of resources in transient

Asynchronous exceptions and management of resources in transient

NOTE: All this has been superseeded by finalizations

I was looking at the last article of Michael Snoyman about asynchronous exceptions. Proper handling of resources in long term programs such are servers demands very accurate management of resources. In transient where many threads are spawned and sometimes killed asynchronously, this is even more important.

So I first tried to create a version of bracket for the transient monad:

bracket
@agocorona
agocorona / transient-url.md
Last active August 21, 2020 23:12
HTTP interface for transient programs

This is a tutorial intended to teach how to invoke any part of a Transient-universe program using HTTP requests. It is also very useful to understand the mechanism of serialization and remote execution of distributed transient programs.

This is not the REST API that is also included in transient-universe. This API is shown in examples like api.hs which Is undocumented but I hope, may be self-explaining.

Note this is the api.hs version for the "new" branch which is being detailed here.

Transient is a library for the language Haskell that allows high-level effects like parallelism, concurrency, asynchronicity, streaming and distributed computing and manage them without special constructions.

@agocorona
agocorona / move.md
Last active October 24, 2022 22:19
Managing Haskell computations as data for storage, restore, translate and distributed computing

Managing Haskell computations as data for storage, restore, translate and distributed computing

This is a tutorial about how to handle the complete state of a computation so that it can be serialized, stored, translated, analyzed, restored his execution etc

This text summarizes my reseach with Transient in this aspect which is the least known. I want to make it public since I belive has useful contributions to real world computing problems in novel ways and may make a difference. The text is the result of a balance between didactic simplicity (my intention) and the terseness of my laziness.

I use a pseudocode similar to Haskell. This is a very first version which will have errors for sure. But it gives an idea. I will perfect the content from time to time to make it more informative. At first it will be a gist.