https://github.com/rexwu1104/lambda
目前還沒設計的很完善,請噴小力一點
#Lambda 一個弱型別的靜態語言
1 messages · Page 1 of 1 (latest)
不過為什麼要弱型別w
他不是嗎
他離線了才不正常
看了下只有grammar definition?
homobot
正在寫parser
我想把python的優點加進去
雀食
腳本語言的部分嗎
靜態容易做嗎?
我會說做出來產生的執行檔會非常肥大
maybe
不然你可以告訴我你預計產生出甚麼樣可以執行的形式
native實現python會超級肥,llvm的話是register-based也不太適合
大概只有bytecode才不會肥大
Cond
::= Value
::= Value CmpOp
::= CmpOp Value
::= Value CmpOp "$" CmpOp Value
::= Cond CondConcat Cond
::= "{" CondSet "|" Cond "}"
::= "{" CondSet ":" Cond "}"
::= Range
::= "?"
::= "_"
CondSet
::= Identifier
::= Identifier "N"
::= Identifier "Z"
::= Identifier "Q"
::= Identifier "R"
::= Identifier "C"
::= Cond
這段定義感覺會毀滅
我猜你的 N Z Q R C 是想代表數學的那些數字集合
但這跟你下面定的 Value 顯然不搭(只有 Number 跟 Float )
而且我不認為有辦法區別 Q 跟 R
好像是耶,好吧
反正那邊還沒做
但 哥 py是強型別
py的優點不是開發簡單嗎
py的優點是他吃很多記憶體
有動態的編譯語言嗎
how
因為靈感從微積分來的
我還以為是```py
func = lambda x: x + 1
bruh
formula "./test.ld"
formula "./test2.ld"
main of () =
boolTest();
symbolTest()
end
boolTest of () =
print 1 > 2;
print 1 < 2;
print 1 == 2;
print 1 >= 2;
print 1 <= 2;
print 1 != 2
end
symbolTest of () =
print 1 + 2;
print 1 - 2;
print 1 * 2;
print 1 / 2;
print 1 % 2;
print 1 ** 2
end
{|$x|}
(||) of x =
>= 0 => x;
< 0 => -x
end
{$x~$y}
(~) of x y = \
x..y
type point = (int int)
type pointS = (x: int y: int)
type pointC: pointS =
@pub _ of x y =
_x = x;
_y = y
end
@pub @property x of () = _x
@pub @property y of () = _y
end
微積分哪裡有 Lambda 了
你要說的484線性代數
因為微積分我就想到數學,因為數學我就想到Lambda

這什麼神奇的邏輯
這又跟右腦什麼關係
沒邏輯
你取名叫做 Lambda
別人就會覺得這是什麼 functional 之類的
確實
然而你的 lambda 寫得很麻煩
上面還沒有
BTW你的README壞了
Lambda ::= "(" Params ")" "->" Expressions "end"
你既然想做 FP
又取名叫做 Lambda
我以為這會是第一個設計的東西#
為什麼要那麼麻煩
口語化是吧
確實
原來這是數學語言
確實
type pointS = (x: int y: int) 這邊 x 跟 y 的用意是什麼
🤔 所以這個 x y 要怎麼使用
這過一下就好了
大概就是有名稱的tuple (struct)?
所以要怎麼用#
像是 Haskell 有所謂的 Record Syntax
data Person = Person { name :: String, age :: Int }
這邊 name 的型別就會是 Person -> String
如果 p = Person "Alice" 20,那麼 name p 就會回傳 "Alice"
也就是說 property 實際上是個函式?
instance.property
<~> instance.property()
<~> Class.property(instance)
你完全可以用函式去理解它
如果你真的想做針對數學訂製的語言你可以看看這玩意
https://youtu.be/Ra_Fk7JFMoo
References:
- Please support those who need it the most right now: https://donate.thedigital.gov.ua/
- Coq: https://coq.inria.fr/
- Derivative: https://en.wikipedia.org/wiki/Derivative
- Noq: https://github.com/tsoding/Noq
就直接回傳一個tuple
可以理解成是tuple但可讀性高的語法糖嗎?
應該可以
因為是靜態定型應該也就不需要名稱
嗯嗯
type Vec<T> = (length: int buf: []T)
Vec<T> of () = (0 []T)
為什麼這個例子可以寫 Vec<T> of ()
constructor的概念?
a = pointS 0 0
a_x
從 functional 的角度上來看好像不是那麼好用
為啥感覺好像```py
class poinsS:
def init(self, x: int, y: int):
self.x = x
self.y = y
因為就是
😂 結果是OO嗎
你應該可以把 type point = (int int) 看成
class point:
def __init__(self, _1: int, _2: int):
self._1 = _1
self._2 = _2
這是給OO的語法糖
…
那...?
不好用的意思是說
如果我想要一個輸入 p : pointS 而回傳 p_x 的函式
我還要額外定義
xOfPointS of (p : pointS) = p_x
因為haskell是用atom?
我看不懂你在說什麼
我不知道為什麼要額外定義
type Point = {x: Int, y: Int}
def makePoint: Int -> Int -> Point = (x) -> (y) -> Point{x, y}
```感覺醬比較好
所以當我寫 type pointS = (x: int y: int) 之後
那 (p : pointS) => p_x 的函式從哪裡來?
我覺得你其實是在搞IP,但是想結合一點所謂的FP特性,像Optional之類的
就直接取
不,我現在在做 functional 的操作,我需要那個函式
編譯器魔法
皮皮應該很想傳拍額頭.gif
99%
什麼是IP?
命令式
喔喔
…打個比方好了
我有一個列表 ps : [pointS],我想要拿到另一個列表 xs : [int],使得我有 xs[i] == ps[i]_x
要得到 xs,functional 語言裡很自然地想法就是用 map 函式:map f ps
這邊的 f 就要是 (p : pointS) => p_x
在不額外定義的情況下,我要如何得到那個 f
_?
f = _x
按他的說法_是一個運算子/函式
嗯嗯
但要像這樣用,_要是「static」
x 的 y 屬性就是 x_y
umm 好
所以是 map (_x) ps?
好怪
如果把 _ 當作運算子的話這樣還能接受
就像是 map (+1) [0..10] 一樣
_是function還是operator?
same thing
(operator 就是一個二元的 function
😂 好像也是
運算子就是比較可讀的函式
嗯嗯
你先別嗯
好
所以 x 在 map (_x) ps 裡面是什麼
對欸,x不是一個在上下文(?)有定義的變數之類的
類似xs = map(.x, ps)?
我不知道 Atom 是啥,聽不懂
token?
對對
對
另一個問題是,我能不能寫 map (p_) [x y]
我猜是built-in var
我覺得把_改成'x' of p會比較好
可以
而且醬的話屬性/欄位名是第一運算元(?
先別急著說可以
好
所以 x y 是啥
編譯器會做推論的動作,所以他會是token
不是
[_.x, _.y] for _ in p?
否
好
token是編譯器切分的「單詞」
其實你做不出來
因為會寫成 [p.i for i in [x, y]]
然後你就會發現 x y 很有問題
而且如果p還不是只有pointS呢
我覺得你在使用沒有共識的術語
Option::None
你說可以寫 map (p_) [x y]
那這邊的 [x y] 該怎麼理解
two atom token
編譯器要怎麼理解
看_出現的地方,以及最多會影響到哪個步驟,然後去推斷
我懷疑你其實沒有那個推斷能力
這只是個目標
天呀,你要做的是弱型別語言欸
在我的經驗裡
你如果想要推斷出什麼
首先你的型別要有足夠豐富的表達能力
而且應該不能太弱
嗯嗯
先說好,我認為編譯器的核心理論是context-based,雖然grammar大部分語言都是採context-free,但對於推論這點context-based所要基於的點會非常多,如果你沒辦法把一個東西明確地給出他的定義,不用說機器,連人類要寫都會很頭痛
TLDR要先有definition才能有usage
而這邊剛剛的map (p_) [x y]我只有看到function map的definition和local variable p_的definition,x 和 y我無法得知他到底有沒有definition
x y同時可能是key of obj也可能是variable
||```
type Point{x: Int, y: Int}
def makePoint: Int -> Int -> Point = x -> y -> Point{x, y}
def xOf: Point -> Int = p -> p.x // Notice this is "static"(?
但如果是「把p的值填進後面的列表[x y]」(?
嗯...我...看不懂
我也

我不覺得這是可行的實作
我其實混亂到看不懂了,函數揉製是FP必須的嗎?
沒關係
這種討論484語音會比較好溝通(前提是願意講話的情況下
你想要靠程式推斷出 [x y] 並不是做不到
不一定,語音沒紀錄
型別表達足夠豐富的語言還是有辦法推斷 [x y] 是什麼:
map : (A -> B) -> [A] -> [B]
(p_) : <key of pointS> -> <value of pointS>
map (p_) : [<key of pointS>] -> [<value of pointS>]
所以 [x y] 必須是 [<key of pointS>]
或許有別的方法也說不定
即時字幕 + log
那你要「說」程式碼嗎
手打輔助咩
或者說,按照你的定義,(p_) (f x) 應該是可以寫出來的
沒記錯他是說s前面有沒有_

意思是說,假設 pointS = (x : int y : int) 且 p : pointS
已知 (p_) x 會是 p_x
那麼能不能寫 ((y) -> (p_) y) x?這樣的結果會是 p_x 還是 p_y?
p_x
為什麼能知道是 p_x
因為最後是x傳進去
我換個寫法ㄛ
好
p x ::= p_x?
Haskell 的 x y z 就是 Python 的 ( x(y) )(z)
嗯...我覺得我應該要換掉使用方法?
我看不懂你說的#
x(y)(z)
||```
def map<T, U> :: (T -> U) -> [T] -> [U] =
f -> ts -> {
if null ts
then []
else f (head ts) : map f (tail ts)
}
沒 來亂的
空格ww 函數呼叫吧
def map ({_prekeys}, iter{_}) {surfkeys}
if prekeys is null
return map (_surfkeys iter)
...
```||(來亂的+1||
假設 p : pointS = (0, 0)
如果我寫 x = 3; p_x
這會得到什麼結果?
0
等價的應該是
def map(f):
return lambda ts:
[] if ts == [] else map(f)(ts[1:]).insert(0, f(ts[0]))
lambda不用return
def map(f):
return lambda ts: [] if ts == [] else map(f)(ts[1:]).insert(0, f(ts[0]))
py的lambda有夠反人類
map = lambda f: lambda ts: [] if ts == [] else map(f)(ts[1:]).insert(0, f(ts[0]))
```(X
確實
然後我發現一個點
假設 p : pointS = (0, 1)
如果我寫 x = 3; map ((f) -> f x) [(y) -> p_y, (z) -> z]
這會得到什麼結果?
因為是靜態定型,所以_只能是編譯器魔法(成員存取運算子),所以p_y導致編譯錯誤?
嗯...那我用另一個方法好了
什麼另一個方法
就算動態也不存在p_3,這不是巨集,因此y不會被x取代掉,大概
就 everything is function
但目前看起來…有點矛盾?
確實
member尋找順序是變數→key?
所以我想改移下
我覺得動態定型會比較好
然後_是接受一個字串,參考Lua的table
我在吃飯,等一下講
並不是只有編譯器魔法能做到這些事
Code:(~~) x f = f x infix 5 ~~ data Point = Point {x :: Int, y :: Int} p = Point 1 3 q = Point 2 6 main = do print $ p ~~ x print $ map (p ~~) [x, y] print $ map (~~ x) [p, q] print $ (\y -> p ~~ y) x(~~) x f = f x infix 5 ~~ data Point = Point {x :: Int, y :: Int} p = Point 1 3 q = Point 2 6 main = do print $ p ~~ x print $ map (p ~~) [x, y] print $ map (~~ x) [p, q] print $ (\y -> p ~~ y) x
Output:```p
[1 of 1] Compiling Main ( .code.tio.hs, .code.tio.o )
.code.tio.hs:1:17: error: parse error on input ‘infix’
|
1 | () x f = f x infix 5 ~~ data Point = Point {x :: Int, y :: Int} p = Point 1 3 q = Point 2 6 main = do print $ p ~~ x print $ map (p ) x f = f x infix 5 ~~ data Point = Point {x :: Int, y :: Int} p = Point 1 3 q = Point 2 6 main = do print $ p ~~ x print $ map (p ) [x, y] print $ map ( x) [p, q] print $ (\y -> p ~~ y) x() [x, y] print $ map ( x) [p, q] print $ (\y -> p ~~ y) x
| ^^^^^
/srv/wrappers/haskell: line 5: ./.bin.tio: No such file or directory
Exit code: 127```
./run
(~~) x f = f x
infix 5 ~~
data Point = Point {x :: Int, y :: Int}
p = Point 1 3
q = Point 2 6
main = do
print $ p ~~ x
print $ map (p ~~) [x, y]
print $ map (~~ x) [p, q]
print $ (\y -> p ~~ y) x
Here is your haskell(9.0.1) output @lilac drum
1
[1,3]
[1,2]
1
我的想法是_可以放入命名裡,然後取變數就是用Atom對變數當參數
a = PointS 0 0
a `x`
p ~~這種為什麼不會出事?是因為惰性求值嗎?
你覺得會出什麼事
二元運算子只有一個運算元…所以p~~是函式?但~~x是什麼
對,但這個順序可以反過來?
oh 這應該可以算是語法糖,對一個中綴的 op
(op y) 代表 \x -> x op y
haskell mentioned
那個應該是 section
(+ 2) = (\x -> x + 2)
(2 +) = (\y -> 2 + y)
我覺得很酷的一個例子:
applyFive = map ($ 5) [(+ 1), (2 ^)]
applyFive = map (\f -> f 5) [(+ 1), (2 ^)]
對,上面的 (~~) 其實就是 flip ($)
還真的有
