Conversation
PointFree/PointFree/PointFree.fs
Outdated
| let f (x : int) = (*) x | ||
| let f_withoutX = f | ||
| let func = f_withoutX >> List.map | ||
| func |
There was a problem hiding this comment.
ожидалась point-free запись без использования промежуточных let.
PhoneBook/PhoneBook/PhoneBook.fs
Outdated
| type Person = | ||
| val Name : string | ||
| val Number : string | ||
|
|
||
| new (name, phone) = { Name = name; Number = phone;} |
There was a problem hiding this comment.
| type Person = | |
| val Name : string | |
| val Number : string | |
| new (name, phone) = { Name = name; Number = phone;} | |
| type Person = { Name: string; Number: string } |
Brackets/Brackets/BracketsChecker.fs
Outdated
| module Brackets = | ||
|
|
||
| let checkSequence (sequence : string) = | ||
| let rec checkRec sequence stack position = |
There was a problem hiding this comment.
пусть стек будет типа char list, это повзолит избежать конкатенаций строк и позволит использовать паттерн-матчинг
Brackets/Brackets/BracketsChecker.fs
Outdated
| if (String.length stack = 0) then false | ||
| else | ||
| if ((bracket = ')' && stack.[0] = '(') || (bracket = ']' && stack.[0] = '[') || (bracket = '}' && stack.[0] = '{')) then |
There was a problem hiding this comment.
нужно использовать паттерн матчинг на stack
Brackets/Brackets/BracketsChecker.fs
Outdated
| else | ||
| let bracket = sequence.[position] | ||
| match bracket with | ||
| | '[' | '{' | '(' -> |
There was a problem hiding this comment.
можно завести отдельные небольшие функции, которые проверят, что скобочка открывающаяся, закрывающаяся и какие скобки образуют пару.
Или, как вариант, Map
| } | ||
|
|
||
| let testCasesFalse = | ||
| seq { |
PhoneBook/PhoneBook/Program.fs
Outdated
| let mutable errors = 0 | ||
| let mutable data = [] |
There was a problem hiding this comment.
нельзя использовать мутабельное состояние
PhoneBook/PhoneBook/Program.fs
Outdated
| let rec ``find name or phone`` code = | ||
| if (errors > 5) then () | ||
| if code = 2 then printfn "enter the name:\n" else printfn "enter the phone:\n" | ||
| let item = Console.ReadLine() | ||
| if (code = 2 && not (name_regex().IsMatch(item)) || code = 3 && not (phone_regex().IsMatch(item))) then | ||
| printfn "incorrect data, try again\n" | ||
| errors <- errors + 1 | ||
| ``find name or phone`` code | ||
| else | ||
| errors <- 0 | ||
| if code = 2 then | ||
| match findByName item data with | ||
| | None -> printfn "%s" "there is no such name\n" | ||
| | Some name -> printfn "%s" (name.ToString()) | ||
| else match findByPhone item data with | ||
| | None -> printfn "%s" "there is no such number\n" | ||
| | Some number -> printfn "%s" (number.ToString()) |
PhoneBook/PhoneBook/Program.fs
Outdated
| To read data from file and save it to phone book press 6:\n" | ||
|
|
||
|
|
||
| let mutable errors = 0 |
There was a problem hiding this comment.
точно ли нам эта логика с ошибками нужна?
PhoneBook/PhoneBook/PhoneBook.fs
Outdated
| if List.exists(fun (p : Person) -> p.Number = person.Number) data | ||
| then data else person :: data |
There was a problem hiding this comment.
я бы делал, в случае добавления дубликата, более очевидный тип ошибки, нежели скрывать её за возвращением того же набора данных
| let comparePersons (p1 : Person) (p2 : Person) = | ||
| if p1.Name < p2.Name then -1 else | ||
| if p1.Name = p2.Name then | ||
| if p1.Number < p2.Number then -1 | ||
| else 1 | ||
| else 1 |
There was a problem hiding this comment.
это не нужно, рекорды сравниваются структурно через обычное =
| let funcInitial x l = List.map (fun y -> y * x) l | ||
| let funcWithoutL1 x = List.map (fun y -> y * x) | ||
| let funcWithoutL2 x = List.map (fun y -> (*) y x) | ||
| let funcWithoutL3 x = List.map << (fun y -> (*) y) <| x |
There was a problem hiding this comment.
| let funcWithoutL3 x = List.map << (fun y -> (*) y) <| x | |
| let funcWithoutL3 x = (List.map << (fun y -> (*) y)) x |
Brackets/Brackets/BracketsChecker.fs
Outdated
| match bracket with | ||
| | '[' | '{' | '(' -> |
There was a problem hiding this comment.
воспользуйтесь bracketPairs.Keys.Contains, чтобы не дублировать логику
Brackets/Brackets/BracketsChecker.fs
Outdated
|
|
||
| let checkSequence (sequence : string) = | ||
| let rec checkRec sequence stack position counter = | ||
| if (position = String.length sequence) then |
There was a problem hiding this comment.
| if (position = String.length sequence) then | |
| if (position = sequence.Length) then |
Brackets/Brackets/BracketsChecker.fs
Outdated
| if (bracket = bracketPairs.[stack.[0]]) then | ||
| checkRec sequence stack.[1..(counter - 1)] (position + 1) (counter - 1) |
There was a problem hiding this comment.
давайте использовать паттерн матчинг, чтобы проверять голову и хвост у stack
| let dataConvertToString = " Tom 89019892909 \n Alice 83890198101 \n John 82839281789 \n Bob +72898271890 \n Hanna +71289019813 \n Sara 81278918789 \n" | ||
| [<Test>] |
There was a problem hiding this comment.
| let dataConvertToString = " Tom 89019892909 \n Alice 83890198101 \n John 82839281789 \n Bob +72898271890 \n Hanna +71289019813 \n Sara 81278918789 \n" | |
| [<Test>] | |
| let dataConvertToString = " Tom 89019892909 \n Alice 83890198101 \n John 82839281789 \n Bob +72898271890 \n Hanna +71289019813 \n Sara 81278918789 \n" | |
| [<Test>] |
И вообще, это data |> List.fold ...? Правда ли, что если мы в data что-то поменяем, а тут нет, беда будет? :)
| (findByName "Sara" data).Value |> should equal "81278918789" | ||
| findByName "Kat" data |> should equal None | ||
|
|
||
| let dataWrite = "Tom 89019892909\nAlice 83890198101\nJohn 82839281789\nBob +72898271890\nHanna +71289019813\nSara 81278918789" |
There was a problem hiding this comment.
Кстати, если оно для одного теста, чтоит внутри теста и объявлять
| open System | ||
| open System.Text.RegularExpressions | ||
|
|
||
| module PhoneBook = |
There was a problem hiding this comment.
Я бы ещё сказал, что надо комментарии
PhoneBook/PhoneBook/PhoneBook.fs
Outdated
| namespace PhoneBook | ||
| open System |
There was a problem hiding this comment.
| namespace PhoneBook | |
| open System | |
| namespace PhoneBook | |
| open System |
PhoneBook/PhoneBook/PhoneBook.fs
Outdated
|
|
||
| type Person = { Name: string; Number: string } | ||
|
|
||
| let phone_regex () = Regex(@"(\+7|7|8)+\d{10}", RegexOptions.Compiled) |
There was a problem hiding this comment.
В .NET используют camelCase, это ж не Питон
PhoneBook/PhoneBook/PhoneBook.fs
Outdated
| let addRecord (person : Person) data = | ||
| if List.exists(fun (p : Person) -> p.Number = person.Number) data | ||
| then | ||
| invalidArg "" "incorrect data: the number already exists" |
There was a problem hiding this comment.
- имя параметра пустое, нехорошо
- в ФП не любят исключения, они неявны и вызывающий может быть неготов к тому, что они бросаются. Сделайте более по-ФПшному
PhoneBook/PhoneBook/Program.fs
Outdated
|
|
||
| Some code | ||
|
|
||
| let rec ``add record`` data = |
| let phoneRegex () = Regex(@"(\+7|7|8)+\d{10}", RegexOptions.Compiled) | ||
| let nameRegex () = Regex(@"[A-Z][a-z]+", RegexOptions.Compiled) | ||
|
|
||
| ///Add new record to the data |
There was a problem hiding this comment.
| ///Add new record to the data | |
| /// Add new record to the data |
PhoneBook/PhoneBook/PhoneBook.fs
Outdated
| let addRecord (person : Person) data = | ||
| if List.exists(fun (p : Person) -> p.Number = person.Number) data | ||
| then | ||
| invalidArg "" "incorrect data: the number already exists" |
No description provided.