warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket before after m = do
x <- before
rs <- try (m x)
after x
case rs of
Right r -> return r
Left e -> ioError e
ไม่เคยเขียนเลย เดี๋ยวรอดูชาวบ้านก่อนดีกว่า จะได้หัด อิอิ
haskell
ไม่เคยเขียนเหมือนกัน
เลยต้องไปหาอ่านดู
โดยทั่วไป เขานิยมการเปิด file แบบที่ automatic ปิดให้ใช่ไหม
อย่างใน ruby
ใน haskell ก็มีอะไรที่คล้ายๆอย่างนั้นเหมือนกัน
เรียกว่า bracket
ใช้อย่างนี้ (ตัวอย่างนี้อ่าน file แล้วพิมพ์ 10 ตัวอักษรแรก)
dumpFile = bracket (openFile "/tmp/pok.txt" ReadMode) hClose (\h -> do contents <- hGetContents h putStrLn (take 10 contents))bracket จะรับ parameter 3 ตัวคือ before, after, m
จากข้างบน (openFile ...) คือ before
hClose คือ after แล้วก็ lambda คือ m
สิ่งที่ bracket ทำก็คือ เรียก before ก่อน ได้ผลลัพท์เป็นอะไรก็ส่งเป็น parameter ให้ m
สุดท้ายก็จบด้วย after (ซึ่งข้างบนก็คือการปิด file)
ถ้าเปิดดูใน haskell library จะเห็นว่าเขา declare bracket ไว้ดังนี้
bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c bracket before after m = do x <- before rs <- try (m x) after x case rs of Right r -> return r Left e -> ioError eหรือผมต้องหัด Haskell บ้างเนี่ย? (ตอนนี้ลุ่มหลง Scheme อยู่ :-P)
php
ืท่านี่ก็เท่ห์ดี :-D
ความจริงถ้ายาวกว่านี้
หรืออ่านไฟล์ทีละบรรทัดเป็นอาเรย์