2021년 8월 20일 금요일

windows에 sqlite 설치하기

sqlite 홈페이지에서 소스코드와 dll을 받아와서 띄어쓰기가 없는 폴더에 풀어둔다. 그 폴더를 FOLDER라고 하면,

chcp 65001

stack install HDBC

stack install sqlite --resolver=lts=11.22  --extra-lib-dirs="FOLDER" --extra-include-dirs="FOLDER"

여기까지는 성공.

stack install HDBC-sqlite3  (X)

stack install HDBC-sqlite3 --resolver=lts-11.22 (X)

stack install HDBC-sqlite3 --extra-lib-dirs="FOLDER" --extra-include-dirs="FOLDER" (X)

stack install HDBC-sqlite3 --resolver=lts-11.22 --extra-lib-dirs="FOLDER" --extra-include-dirs="FOLDER" (X)

모두 같은 error...

describeCol (_:name:typ:notnull:df:pk:_) =

 참고로, ubuntu에서도 동일한 error가 일어난다. 


2021.08.23.

HDBC-sqlite3> Database\HDBC\Sqlite3\Connection.hs:81:1: error:
HDBC-sqlite3>     <stderr>: commitAndReleaseBuffer: invalid argument (invalid character)

의 error message로 바뀜. 모두 동일.

2014년 9월 21일 일요일

Error in installing memoize package

Haskell의 메모화(memoize) 패키지 설치시 다음과 같은 error가 난다.
$ cabal install memoize
Resolving dependencies...
Downloading memoize-0.6...
Configuring memoize-0.6...
Building memoize-0.6...
Preprocessing library memoize-0.6...
Data/Function/Memoize/TH.hs:5:6:
     error: invalid preprocessing directive
        #-}
         ^
#-}를 코드 윗줄로만 옮겨주면 된다. Mac에서만의 문제인 듯 하다.
이는 LLVM의 clang을 기본으로 사용하는 Xcode 때문인 것이라고 한다. 분명 신버전의 Haskell Platform은 clang과 gcc를 모두 지원한다고 하는데... 암튼 에러가 났다.

  1. cabal install memoize 하면 ~/Library/Haskell에 memoize 폴더가 생성되어 있을 것임.
  2. memoize 폴더로 이동해, memoize-0.6.tar.gz를 해동.
  3. TH.hs를 열어 5번째 줄에 있는 #-}를 코드 4번째 줄 맨 뒤로 위치시킴.
  4. 저장 & 수정된 파일로 memoize-0.6.tar.gz를 만들어줌.
  5. cabal install memoize 실행.


2014년 9월 16일 화요일

Euler Project: Problem 31

In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
It is possible to make £2 in the following way:
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
How many different ways can £2 be made using any number of coins?


main = print $ length $ coinSum 200 
coinSum n = [ [oneP, twoP, fiveP, tenP, twentyP, fiftyP, oneL, twoL] |
    oneP    <- [0 .. n],
    twoP    <- [0, 2 .. n - oneP],
    fiveP   <- [0, 5 .. n - (oneP + twoP)],
    tenP    <- [0, 10 .. n - (oneP + twoP + fiveP)],
    twentyP <- [0, 20 .. n - (oneP + twoP + fiveP + tenP)],
    fiftyP  <- [0, 50 .. n - (oneP + twoP + fiveP + tenP + twentyP)],
    oneL    <- [0, 100 .. n - (oneP + twoP + fiveP + tenP + twentyP + fiftyP)],
    twoL    <- [0, 200 .. n - (oneP + twoP + fiveP + tenP + twentyP + fiftyP + oneL)],
    oneP + twoP + fiveP + tenP + twentyP + fiftyP + oneL + twoL == 200] 
*Main> main
73682


2014년 5월 6일 화요일

Euler Project: Problem 30

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44
As 1 = 14 is not a sum it is not included.
The sum of these numbers is 1634 + 8208 + 9474 = 19316.
Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

import Data.Char 
main :: IO()
main = print $ sum $ map snd $ filter fst resultData 
resultData :: [(Bool, Int)]
resultData = map (\x -> (compareDigit $ show x, x)) inputData 
compareDigit :: String -> Bool
compareDigit s = s == digitPowerSum s 
digitPowerSum :: String -> String
digitPowerSum n = show . sum $ map (\x -> digitToInt x ^5) n 
inputData :: [Int]
inputData = [2..6*9^5] 
*Main> main
443839


2014년 5월 5일 월요일

Numerical type 사이의 변환 방법

Numerical Type 사이의 전환에 대해서 정리해 보았다.
여기(영어)와 여기(일어)의 정리가 잘 되어 있다.

고졸 수학실력에 알맞게 내가 알고 있는 숫자 형태, 예를 들면 정수, 분수, 소수, 부동소수로 분류하여 각각의 type 변환을 그림으로 정리해 보았다.


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: 주말까지 작성.

Euler Project: Problem 29

Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:
22=4, 23=8, 24=16, 25=32
32=9, 33=27, 34=81, 35=243
42=16, 43=64, 44=256, 45=1024
52=25, 53=125, 54=625, 55=3125
If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:
4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
How many distinct terms are in the sequence generated by ab for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?

Prelude Data.List> length $ nub $ [a^b | a <- [2..100], b <- [2..100]]
9183