Programming 515

F#과 Haskell의 type inference 비교

F#의 type inference는 Haskell을 쓸 때보다 주의할 점이 있다. 예제로, 수 목록을 구간 목록으로 변환하는 프로그램을 작성해보았다. F#에서는 이렇게 리스트에 대해 .[0]을 사용하면 타입 선언 없이는 컴파일되지 않는다: let addToIntervals (intervals: (int * int) list) (n: int) = if not intervals.IsEmpty && n = (fst intervals.[0]) - 1 then (n, (snd intervals.[0])) :: (List.tail intervals) else (n, n) :: intervals let toIntervals (nums: int list) = List.fold addToIntervals [] (List..

Programming 2023.09.21

(C++) variant와 monostate

variant의 첫 번째 타입으로 monostate를 주면 variant 자체에 디폴트 값이 생겨서 디폴트 값을 부여하지 않아도 된다. 예제: #include #include #include struct S { S(int i) : i(i) {} int i; }; int main() { // Without the monostate type this declaration will fail. // This is because S is not default-constructible. std::variant var; assert(var.index() == 0); try { std::get(var); // throws! We need to assign a value } catch(const std::bad_vari..

Programming 2023.09.07

Continuations in Common Lisp. An introductory guide, using the… | by Ashok Khanna | Medium

Continuations in Common Lisp. An introductory guide, using the… | by Ashok Khanna | Medium Continuations in Common Lisp An introductory guide, using the continuation-passing macros of Paul Graham’s On Lisp ashok-khanna.medium.com Continuations in Common Lisp An introductory guide, using the continuation-passing macros of Paul Graham’s On Lisp Ashok Khanna · Follow 7 min read · Aug 17, 2021 62 Co..

Programming 2023.09.07

[c++]리스트 sort 하는 방법 (tistory.com)

[c++]리스트 sort 하는 방법 (tistory.com) [c++]리스트 sort 하는 방법 C++ #include #include int main() { std::list lst; lst.push_back(5); lst.push_back(1); std::sort(lst.begin(), lst.end()); return 0; } 당연하다는 듯이 이런 코드를 작성한 적이 있는데 sort 부분에서 에러가 뜬다. 이유는 아래와 blossoming-man.tistory.com C++ #include #include int main() { std::list lst; lst.push_back(5); lst.push_back(1); std::sort(lst.begin(), lst.end()); return 0; ..

Programming 2023.08.20