[완료]Ocaml 간단한 예제 코드 해석
글쓴이: kid1402 / 작성시간: 수, 2010/09/15 - 10:59오후
Ocaml 관련 원서의 1장에 나오는 예제 코드 입니다.....만, 시작장부터 난해한 명령어 및 기호들이 나오는데 정작 이에 대한 제대로된 설명이 없어서 어려움을 겪고 있습니다..(몇장 몇절에서 다루겠다는 레퍼런스 조차 없네요..)
혹시 Ocaml에 익숙하거나 아시는분들은 다음 코드의 주석부분에 달린 저의 질문에 대답해주시면 정말 감사하겠습니다 ㅠㅠ..
코드 자체는 간단한 소팅 코드입니다
# let rec sort lst = # match lst with (* match .. with .. 이 정확히 어떤 명령어 인가요? *) # [] -> [] (* [] 는 리스트 같긴한데.. ->의 의미는 무엇인가요? *) # | head :: tail -> insert head (sort tail) (* 앞의 | 가 C에서 처럼 or 을 뜻하나요? 그리고 insert의 인자에 ( ) 가 올수있나요? *) # and insert elt lst = # match lst with # [] -> [elt] (* []는 빈 리스트라고 알고 있습니다.. 그럼 [elt]는 elt하나를 인자로 가지는 리스트 인가요? *) # | head :: tail -> if elt <= head then elt :: lst else head :: insert elt tail ;;
간단한 기본 개념 (let, rec, :: 등)은 알고 있습니다.. 하지만 함수적 언어를 처음 접하는 지라 이해하기가 상당히 힘드네요
많은 도움 바랍니다 ㅠㅠ
Forums:
아.. 이렇게 멍청할수가..
자문자답이긴 하지만 , match ... with ... | ... 의 쓰임새가 있다는걸 찾았습니다..
댓글 달기