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/01 20:28] – [Explanation, step by step] f2b216codesnippets:firsthaskellprogram [2025/10/08 00:48] (current) – external edit 127.0.0.1
Line 2: Line 2:
  
   * 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 25: 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 47: 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 67: 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.
-    * Type sigantures can also have type parameters, and its type constraints.+    * Type signatures can also have type parameters, and type constraints.
     * Type type parameters start always with lower case letters.     * Type type parameters start always with lower case letters.
   * the example executes with the following output:   * the example executes with the following output:
Line 83: 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' ''
  
-==== 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.1617301736.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