a = [1,2,3,4]
b = a << 5
a == [1,2,3,4] # returns false
Run Code Online (Sandbox Code Playgroud)
如何分配b到a与5追加到末尾,而无需修改a本身?
(我是初学者)Python通常使用缩进来指定代码行的嵌套级别.有没有其他方法可以做到这一点?
module Digits
type Digit = Unison | Semitone | Tone | MinorThird | MajorThird | PerfectFourth | AugmentedFourth | PerfectFifth | MinorSixth | MajorSixth | MinorSeventh | MajorSeventh type 'd GeneralizedDigit = SmallDigit of 'd | Octave type 't Number = EmptyNumber | CountedNumber of 't * 't Number
let swapOctave: Digit GeneralizedDigit -> Digit GeneralizedDigit = fun x -> match x with SmallDigit Unison -> Octave | Octave -> SmallDigit Unison | g -> g
let limitLength: 'r Number …Run Code Online (Sandbox Code Playgroud) 我在Monad.Reader问题22中找到了这个:
data Color = R | B
data Node a = E | N Color (Node a) a (Node a)
type Tree a = Node a
Run Code Online (Sandbox Code Playgroud)
为什么不呢?
data Node a = E | N Bool (Node a) a (Node a)
type Tree a = Node a
Run Code Online (Sandbox Code Playgroud)