วันศุกร์ที่ ๒๑ มีนาคม พ.ศ. ๒๕๕๑

ลองศึกษา DDC สักวัน

ผม feed news จาก PLNews พบ DDC Alpha 1 ออกแล้ว เซ็งๆ อยู่เลยมาลองศึกษาดูกัน

DDC อ่านดูจากเวบเค้าบอกว่าเป็น explicitly lazy dialect ของ Haskell

แล้ว explicitly lazy dialect นี่มันอะไรหว่า ส่วน Haskell คือภาษาคอมพิวเตอร์ ภาษานึง ซึ่งเค้านิยามตัวเองว่าเป็น advanced purely functional programming language เจอศัพท์ใหม่อีกละ แล้วไอ้เจ้า

Functional programming

นี่มันคือไร

เอาละ มาเริ่มศึกษา Functional Programming กันก่อน เพราะรู้จักแต่ VB, Delphi ไรประมาณนี้

Functional Programming Language เป็นรูปแบบนึงในการเขียนโปรแกรมซึ่งไม่เหมือนกันกับวิธีที่เค้าเรียกกันว่า imperative ((อิมเพอ' ระทิฟช) adj. ซึ่งเลี่ยงไม่ได้, จำเป็น, เชิงบังคับ -n. คำสั่ง, ความจำเป็น, ข้อบังคับ, กฎเกณฑ์, น้ำเสียงขอร้องหรือเป็นเชิงบังคับ, มาลาเชิงบังคับของไวยากรณ์) programming models ซึ่งจะมีการ evaluation ของexpressions (นิพจน์) ทั้งหมดที่พูดมานี่ ไม่ว่าจะเป็น Functional programming language , imperative programming , etc.... นั้นมันก็คือ

Programming Language Concepts นั่นเอง นั่นคือ ภาษาคอมพิวเตอร์ต่างๆ ที่ได้สร้างขึ้นมานั้นก็จะมีการออกแบบโดยได้วาง concept ไว้ต่างๆกัน ที่นี้ถ้าเรามาลองดูว่ามันมี กี่ประเภทจาก wikipedia นะ เพียบเลยดังนี้

  • 1 Array languages
  • 2 Aspect-oriented languages
  • 3 Assembly languages
  • 4 Authoring languages
  • 5 Command line interface languages
  • 6 Compiled languages
  • 7 Concurrent languages
  • 8 Curly-bracket languages
  • 9 Dataflow languages
  • 10 Data-oriented languages
  • 11 Data-structured languages
  • 12 Declarative languages
  • 13 Esoteric languages
  • 14 Extension languages
  • 15 Fourth-generation languages
  • 16 Functional languages
  • 17 Interactive mode languages
  • 18 Interpreted languages
  • 19 Iterative languages
  • 20 List-based languages – LISPs
  • 21 Little languages
  • 22 Logic-based languages
  • 23 Machine languages
  • 24 Macro languages
  • 25 Metaprogramming languages
  • 26 Multiparadigm languages
  • 27 Numerical analysis
  • 28 Non-English-based languages
  • 29 Object-oriented class-based languages
  • 30 Object-oriented prototype-based languages
  • 31 Off-side rule languages
  • 32 Procedural languages
  • 33 Reflective languages
  • 34 Rule-based languages
  • 35 Scripting languages
  • 36 Stack-based languages
  • 37 Synchronous languages
  • 38 Syntax handling languages
  • 39 Visual languages
  • 40 Wirth languages
  • 41 XML-based languages
  •  

    ที่แสดงมามันเป็นเพียงวิธีการหรือรูปแบบนึงของ อืมม เค้าเรียนกว่า Programming paradigm แต่ละแบบ กลับมาที่เรื่อง imperative programming ค้นข้อมูลเพิ่มเติมจะพบว่า จริงๆ มันก็คือ procedural programming อ่าา แบบนี้ก็น่าจะคุ้น เพราะคิดว่าเราคงผ่าน โปรแกรมภาษาต่างที่เป็นแบบ procedural มาแล้วไม่ว่าจะเป็น C,Pascal,VB...

    ย้อนนนนนกลับมาที่ Functional Programming มีคนแปลเป็นภาษาไทย ว่าคือ "ภาษาโปรแกรมเชิงหน้าที่" ผมค้นหาข้อมูลจาก เวบ ม.เกษตร ซึ่งอาจารย์เค้าอธิบายว่ามีลักษณะดังนี้

    - ใช้หลักการของฟังก์ชันทางคณิตศาสตร์

    องค์ประกอบของภาษา (Components)

    1. ใช้การเรียกฟังก์ชันมาทำงาน แทนการระบุในรูปคำสั่ง
    2. เป็นลักษณะการทำงานตามหน้าที่ (Functional)
    3. มีองค์ประกอบดังนี้
    • ฟังก์ชันเบื้องต้น (Primitive Function)
    • รูปแบบของฟังก์ชัน (Functional Forms)
    • วิธีดำเนินการ (Application Operation)
    • ออบเจกต์ (Object)

    สรุป

      ข้อแตกต่างระหว่าง Imperative VS Functional
    1. แนวคิดพื้นฐานของการสร้างโปรแกรม
    2. เวลาที่ใช้ในการทำงาน
    3. การเขียนโปรแกรม
    4. ประสิทธิภาพของภาษา

    ย้อนอีกที กลับไปที่ภาษา Haskell ซึ่งอ่านประวัติดูก็คงทราบว่า มันมีมานมนานนกาเล ยี่สิบกว่าปีแล้ว ป้าาาดนี่ถ้าดู ตัว Compiler ที่แสดงนี่มีหลายตัวเลย

    อะตัวสุดท้ายนี่ คุ้นๆ เพราะตรงกะ หัวข้อละ

    พออ่านถึงตรงนี้ ถึงรู้ว่า กรู หาเครื่องเล่นไม่ได้

    ---------------------------------------------------  The Disciplined Disciple Compiler: Build and installation instructions.
    ---------------------------------------------------
    0) You will need working copies of GHC (at least 6.8.1) and GCC installed.

    1) Download the source.

    Either:
    a) grab the source tarball from http://code.google.com/p/disciple

    b) or use darcs to get the head branch:

    $ darcs get http://code.haskell.org/~benl/disciple-HEAD

    2) Make a local copy of the build config file.

    $ cp make/config.mk.sample make/config.mk

    3) Edit this make/config.mk file to set your target system.

    4) Build the compiler, runtime system and external libraries.

    $ make

    5) Build the ddc libraries and run the test code (with optimisations enabled)

    $ bin/war -ddc O

    6) Copy the compiler binary to your ~/bin dir
    (where ~/bin is in your PATH)

    $ mkdir ~/bin
    $ cp bin/ddc ~/bin/ddc.real

    7) For Mac OS X: Copy the runtime library to your ~/lib dir

    $ mkdir ~/lib
    $ cp runtime/libddc-runtime.dylib ~/lib

    8) Create an alias to give ddc the path to its libraries and (static) runtime.
    (You'll probably want to add this to your .profile, or similar)

    $ alias ddc='~/bin/ddc.real -basedir $(DDC_BUILD)' (for bash)
    $ alias ddc '~/bin/ddc.real -basedir $(DDC_BUILD)' (for c shells)



    9) Compile and run your first program

    $ echo 'main () = println "Hello world"' > Main.ds
    $ ddc -make Main.ds -o hello
    $ ./hello

    ---------------------------------------------------
    see doc/HACKING for more info or go to http://code.google.com/p/disciple
    ---------------------------------------------------

    0 ความคิดเห็น: