User Tools

Site Tools


codesnippets:firsthaskellprogram

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
codesnippets:firsthaskellprogram [2021/04/10 13:51] f2b216codesnippets:firsthaskellprogram [2025/10/08 00:48] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== First Haskell programs ====== ====== First Haskell programs ======
-~~DISCUSSION~~ 
  
   * main function with output, as a complete code example   * main function with output, as a complete code example
-    * which compiles +    * compiles, error and warning freewith compiler: GHC 8.10.4using compiler option -Wall
-    * warning free with +
-      * compiler: GHC 8.10.4 using -Wall+
     * <code Haskell>     * <code Haskell>
 main :: IO () main :: IO ()
Line 26: Line 23:
       * whereas ''print'', is a function that is imported from a default package       * whereas ''print'', is a function that is imported from a default package
       * and 'x' is the character ''x''       * and 'x' is the character ''x''
-    * default package is ''prelude''+    * default package is ''[[codesnippets:prelude|Prelude]]''
     * in the second line ''main'', ''print'', and '''x' '' are functions     * in the second line ''main'', ''print'', and '''x' '' are functions
       * ''main'' has no parameter but has type ''IO ()''       * ''main'' has no parameter but has type ''IO ()''
Line 48: Line 45:
  
   * ''IO ()'' is just a type signature with the resulting type ''IO ()'', and no parameters   * ''IO ()'' is just a type signature with the resulting type ''IO ()'', and no parameters
-  * see the following example to explan:+  * see the following code as examples for different type signatures:
     * <code Haskell>     * <code Haskell>
 main :: IO () main :: IO ()
Line 68: Line 65:
       * result type: ''IO ()'', no parameter       * result type: ''IO ()'', no parameter
     * ''String -> IO ()''     * ''String -> IO ()''
-      * result type: ''IO ()'', type of parameter ''String''+      * result type: ''IO ()'', type of parameter''String''
     * ''String''     * ''String''
       * result type: ''String''       * result type: ''String''
     * ''Int -> Char -> String''     * ''Int -> Char -> String''
-      * result type: ''String'', type of first parameter ''Int'', type of second parameter ''String''+      * result type: ''String'', type of first parameter''Int'', type of second parameter''String''
   * NOTE:   * NOTE:
     * Types start always with upper case letters.     * Types start always with upper case letters.
Line 84: Line 81:
 ==== second line declares that function ''main'' equals to ''print 'x''' ==== ==== second line declares that function ''main'' equals to ''print 'x''' ====
  
-  * expression '' main = print 'x' '' is called a [[codesnippets:binding|binding]]+  * expression '' main = print 'x' '' is called a [[codesnippets:bindingandpatternmatching|binding]]
     * it binds ''print 'x' '' to function ''main''     * it binds ''print 'x' '' to function ''main''
     * when function ''main'' evaluates it evaluates ''print'' with parameter '''x' ''     * when function ''main'' evaluates it evaluates ''print'' with parameter '''x' ''
-  * expression ''sResult = fun 5 'a' '' is just another [[codesnippets:binding|binding]]+  * expression ''sResult = fun 5 'a' '' is just another [[codesnippets:bindingandpatternmatching|binding]]
     * it binds ''fun 5 'a' '' to function ''sResult''     * it binds ''fun 5 'a' '' to function ''sResult''
     * when function ''sResult'' evaluates it evaluates ''fun'' with parameter ''5'' and '''a' ''     * when function ''sResult'' evaluates it evaluates ''fun'' with parameter ''5'' and '''a' ''
Line 93: Line 90:
 ==== default package is Prelude ==== ==== default package is Prelude ====
  
-  * ''Prelude'' is part of library ''base'' ([[https://hackage.haskell.org/package/base-4.15.0.0/docs/Prelude.html|Prelude]]) +  * ''[[codesnippets:prelude|Prelude]]'' is part of library ''base'' ([[https://hackage.haskell.org/package/base-4.15.0.0/docs/Prelude.html|Prelude]]) 
-  * package ''Prelude'' includes standard modules (e.g. module System.IO)+  * package ''[[codesnippets:prelude|Prelude]]'' includes standard modules (e.g. module System.IO)
   * enables basic elements like functions, types, type classes, and instances   * enables basic elements like functions, types, type classes, and instances
   * the import of such elements can be controlled in different ways   * the import of such elements can be controlled in different ways
     * see also [[codesnippets:avoidconflictprelude|Avoiding name conflict with Prelude]]     * see also [[codesnippets:avoidconflictprelude|Avoiding name conflict with Prelude]]
  
 +
 +===== ✎ =====
 +~~DISCUSSION~~
  
codesnippets/firsthaskellprogram.1618055492.txt.gz · Last modified: (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki