3
私はPersistentソースコードをブラウズしていましたが、ファイルQuasi.hsの下にこの関数があります(masterブランチの現在の状態にある関連するコードを持つタグを参照しました。これはタグのコードが変更されそうにないためです)。 takeConstraint ps tableName defs (n:rest) | not (T.null n) && isUpper (T.head n) = takeConstraint'
行には、引数のパターンの後にこのパイプ(|)文字があります。 |
と=
の間の式は、パターンの引数の制約と同じですか?ですから、私はこの|
を数学の同じ記号として解釈しますか?つまり、"など"?ハスケル:関数関数を拘束する|
takeConstraint :: PersistSettings
-> Text
-> [FieldDef]
-> [Text]
-> (Maybe FieldDef, Maybe CompositeDef, Maybe UniqueDef, Maybe UnboundForeignDef)
takeConstraint ps tableName defs (n:rest) | not (T.null n) && isUpper (T.head n) = takeConstraint' --- <<<<< This line
where
takeConstraint'
| n == "Unique" = (Nothing, Nothing, Just $ takeUniq ps tableName defs rest, Nothing)
| n == "Foreign" = (Nothing, Nothing, Nothing, Just $ takeForeign ps tableName defs rest)
| n == "Primary" = (Nothing, Just $ takeComposite defs rest, Nothing, Nothing)
| n == "Id" = (Just $ takeId ps tableName (n:rest), Nothing, Nothing, Nothing)
| otherwise = (Nothing, Nothing, Just $ takeUniq ps "" defs (n:rest), Nothing) -- retain compatibility with original unique constraint
takeConstraint _ _ _ _ = (Nothing, Nothing, Nothing, Nothing)
'case'は、同様に私のために良く見えます。 – chi
私は、ガードが少し誤解を招くようになった後で、全体の機能ブロックを詰め込んで、ハスケルから全く新しい機能だと思ったことに同意します。 – Rafael