2014년 5월 5일 월요일

undefined 대신에 $notImplemented 또는 ($todo "주절주절")

Haskell code를 만들어갈 때 함수의 type만 작성하고 본체는 undefined로 두는 경우가 자주 있다. 예를 들면,

someFunction :: a -> b
someFunction = undefined

함수 본체 작성을 잊은 경우, 프로그램 실행시에 불친절한 error가 출력된다. compile시에는 문제없이 넘어간다.

shAegis:Haskell shaegis$ ghc myUtil.hs
[1 of 1] Compiling Main             ( myUtil.hs, myUtil.o )
Linking myUtil ...
shaegis$ ./myUtil
myUtil: Prelude.undefined

Development.Placeholders를 이용하면 compile시에도 error를 잡아주며 undefined된 위치까지 알려준다.

{-# LANGUAGE TemplateHaskell #-}
import Development.Placeholders 
someFunction :: a -> b
someFunction = $notImplemented 
Or 
someFunction = $(todo "주말까지 작성.")

compile을 하면 다음과 같이 error를 잡아준다.

shAegis:Haskell shaegis$ ghc myUtil.hs
[1 of 1] Compiling Main             ( myUtil.hs, myUtil.o )
myUtil.hs:24:17: Warning: Unimplemented feature
Linking myUtil ... 
Or 
myUtil.hs:24:19: Warning: TODO: 주말까지 작성.

댓글 없음:

댓글 쓰기