Giter Site home page Giter Site logo

magic-in-ten-mins-py's Introduction

magic-in-ten-mins-py

十分钟魔法练习 Python 版

纯属娱乐,不保证全部正确性、准确性,以及Python特性使用的简洁性 (`∀´)Ψ,使用部分 Python3.10 的内容

执行所有test case

PYTHONPATH="${PYTHONPATH}:/path/to/project" pipenv run pytest

十分钟魔法练习

Java 版(原版,有不清楚的内容找他) - 玩火

Rust 版 - 光量子

C++ 版 - 图斯卡蓝瑟

C# 版 - CWKSC

Lua 版 - Ofey Chan

Ocaml 版 - 光吟

抽象与组合

希望能在十分钟内教会你一样魔法

QQ群:1070975853 | Telegram Group

目录中方括号里的是前置技能。

类型系统

偏易 | Markdown | 代数数据类型(Algebraic Data Type) [Python 基础]

偏易 | Markdown | 广义代数数据类型(Generalized Algebriac Data Type) [Python 基础, ADT]

偏易 | Markdown | 余代数数据类型(Coalgebraic Data Type) [Python 基础, ADT]

偏易 | Markdown | 单位半群(Monoid) [Python 基础]

较难 | Markdown | 高阶类型(Higher Kinded Type) [Python 基础]

中等 | Markdown | 单子(Monad) [Python 基础, HKT]

较难 | Markdown | 状态单子(State Monad) [Python 基础, HKT , Monad]

中等 | Markdown | 简单类型 λ 演算(Simply-Typed Lambda Calculus) [Python 基础, ADT ,λ 演算]

中等 | Markdown | 系统 F(System F) [Python 基础, ADT ,简单类型 λ 演算]

中等 | Markdown(doc/SysFO.md) | 系统 F ω(System F ω) [Python 基础, ADT ,系统 F]

较难 | Markdown(doc/CoC.md) | 构造演算(Calculus of Construction) [Python 基础, ADT ,系统 F ω]

偏易 | Markdown(doc/PiSigma.md) | π 类型和 Σ 类型(Pi type & Sigma type) [ADT ,构造演算]

计算理论

较难 | Markdown | λ 演算(Lambda Calculus) [Python 基础, ADT]

较难 | Markdown(doc/DBI.md) | De Bruijn 索引(De Bruijn index) [Python 基础,ADT,λ 演算]

偏易 | Markdown | 求值策略(Evaluation Strategy) [Python 基础, λ 演算]

较难 | Markdown | 丘奇编码(Church Encoding) [λ 演算]

很难 | Markdown(doc/ScottE.md) | 斯科特编码(Scott Encoding) [构造演算, ADT , μ]

中等 | Markdown | Y 组合子(Y Combinator) [Python 基础,λ 演算,λ 演算编码]

中等 | Markdown(doc/Mu.md) | μ(Mu) [Python 基础,构造演算, Y 组合子]

中等 | Markdown(doc/VecFin.md) | 向量和有限集(Vector & FinSet) [构造演算, ADT ,依赖类型模式匹配]

形式化验证

偏易 | Markdown(doc/CHIso.md) | Curry-Howard 同构(Curry-Howard Isomorphism) [构造演算]

偏难 | Markdown(doc/LeiEq.md) | 莱布尼兹相等性(Leibniz Equality) [构造演算]

编程范式

简单 | Markdown | 表驱动编程(Table-Driven Programming) [简单 Python 基础]

简单 | Markdown | 续延(Continuation) [简单 Python 基础]

中等 | Markdown | 代数作用(Algebraic Effect) [简单 Python 基础,续延]

中等 | Markdown | 依赖注入(Dependency Injection) [Python 基础, Monad ,代数作用]

中等 | Markdown | 提升(Lifting) [Python 基础, HKT , Monad]

编译原理

较难 | Markdown(doc/ParserM.md) | 解析器单子(Parser Monad) [Python 基础, HKT , Monad]

中等 | Markdown(doc/Parsec.md) | 解析器组合子(Parser Combinator) [Python 基础, HKT , Monad]

magic-in-ten-mins-py's People

Contributors

penguin-wwy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

magic-in-ten-mins-py's Issues

1 里面可以用 dataclass 简化代码

py 的枚举类比较弱。所以需要用 Union 或者 | 来表达和类型。(利用继承的思路学到了)

from __future__ import annotations

import enum
from dataclasses import dataclass
from typing import Union


@dataclass
class Student:
    name: str
    id: int


@dataclass
class Teacher:
    name: str
    office: str


SchoolPerson = Union[Student, Teacher]


class Bool(enum.Enum):
    TRUE = enum.auto()
    FALSE = enum.auto()


def test_bool():
    b = Bool.FALSE
    match b:
        case Bool.TRUE:
            ...
        case Bool.FALSE:
            print("oh my?")


test_bool()


@dataclass
class O:
    ...


@dataclass
class S:
    x: Nat

    def __repr__(self) -> str:
        def count(x: Nat):
            match x:
                case S(x):
                    return 1 + count(x)
                case O():
                    return 0

        return str(count(self))


Nat = S | O


print(S(S(S(S(O())))))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.