Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Busy reading papers

Poscat poscat0x04

💭
Busy reading papers
  • A Mathematical Universe
View GitHub Profile
View concurrency-2.md

Modern haskell - Concurrency (2)

前言

上篇文章简单的介绍了一下 Haskell (GHC) 提供的 user-level concurrency primitives, 这篇将介绍 Haskell 的异常与资源管理。本文默认读者对其他语言中的异常有一定了解。

异常

众所周知,处理异常是非常 impure 的(这里将 purity 定义为 confluence modulo exceptions and non-terminations), 而且 haskell 已经有处理异常的方式了: EitherExceptT, 为什么还需要加入 exception 呢?

View inject.hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
View idris2.nix
{ pkgs ? import <nixpkgs> {}, stdenv ? pkgs.stdenv, idrisPackages ? pkgs.idrisPackages }:
let
idris-builder = idrisPackages.with-packages (with idrisPackages; [ contrib ]);
in stdenv.mkDerivation {
name = "idris2";
version = "0.0.0";
buildInputs = with pkgs; [ idris-builder clang chez gmp ];
View What I dislike about Haskell.md
  1. Crappy record system: no constructor/field overloading, no dot syntax, no row polymorphism
  2. Crappy module system There's backpack, apparently
  3. CPP -- this could be solved by pragmas
  4. Crappy dependent type support
    1. Boilerplate & Code duplication
    2. No totality checking
    3. Crappy type system (Type :: Type, Weak type-level functions)
    4. Barely usable typed holes, extreamly bad editor integration
    5. Weird behaviors when checking GADTs
  5. Over restrictive typeclass resolution (no backtracking, crappy termination checking leading to unnecessary use of UndecidableInstances)
View concurrency-1.md

Modern Haskell - Concurrency

dedication

When the limestone of imperative programming has worn away, the granite of functional programming will be revealed underneath -- Simon Peyton Jones

前言

虽然 Haskell 拥有丰富而成熟的并发特性,但在平时交谈时这些特性似乎很少被提到。因此我想通过 Concurrency 系列文章从用户角度科普一下 Haskell 的并发编程的特性 (先从 User-level concurrency primitives 讲起)。本文将默认读者对 Haskell 和并发编程有基本的了解。

View CompoundParam.hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
View Common patterns in Haskell C FFI design.txt
This is a draft for a future blog post and might be deleted at any time.
Audiances are assumed to be familiar with the c2hs library and Haskell c ffi and have basic knowledge of c.
1. Overall design
I would suggest to do a two-layer design, that is one-level for binding and basic marshalling and one-level for abstraction.
2. Representing C datatypes in Haskell
When designing FFI, you almost always need to represent C datatypes as some Haskell datatypes. You'll need to further add Storable
instance for that Haskell type if you need to marshal between C and Haskell. Associating a C type with Haskell is relatively easy
with c2hs so I'll only cover the marshalling part.
View Why functional matters
This is my philosophical argument on why functional programming matters.
1. Abstraction
Functional programming unlocks a whole varieties of abstractions (monads, arrows and profunctors for example) that are meaningless to
mimic or impractical and unable to implement in imperative languages. These abstractions help us to tackle and understand a complex
software system to effectively reduce the complexity
(insert notation as a tool of thought citation)
2. Constraints
Funcitonal programming let us specify what exactly a program can do and cannot do -- type signatures, class constraints, dependent types,
View gist:351941d57dbf81ab1b0b1e89f68f654f
### Keybase proof
I hereby claim:
* I am poscat0x04 on github.
* I am poscat0x04 (https://keybase.io/poscat0x04) on keybase.
* I have a public key ASDsfH6LS2VtPnjb1_L4BMmU-iCSPEnFQJv_om7MPslixgo
To claim this, I am signing this object:
@poscat0x04
poscat0x04 / avahi-generate.py
Last active May 24, 2020
Airprint zeroconf service generating script (python3 ver)
View avahi-generate.py
#!/usr/bin/env python
"""
Copyright (c) 2010 Timothy J Fontaine <tjfontaine@atxconsulting.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is