Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7491805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:10:44+00:00 2026-05-29T16:10:44+00:00

Many of the Haskell tutorials I’ve looked through focus almost entirely on syntax with

  • 0

Many of the Haskell tutorials I’ve looked through focus almost entirely on syntax with very little coverage on how to structure a program.

For example…

Here’s a bare-bones outline of a C++ application:

#include <iostream>
using namespace std;

int addition (int a, int b)
{
  int r;
  r=a+b;
  return (r);
}

int main ()
{
  int z;
  z = addition (5,3);
  cout << "The result is " << z;
  return 0;
}

When I first started learning C++, examples like these helped me immensely in learning how to assemble individual pieces into working programs. Maybe I’m looking in the wrong places, but I haven’t been able to find any such examples that are as direct and simple for Haskell.

I already know A LOT of Haskell syntax. I can write recursive list comprehensions, and manipulate strings, integers, and lists out the wazoo.

In short: I just want to know what two subroutines and variable pass looks like in Haskell. If I can get some basic understanding on how to structure a Haskell program, I might finally be able to put all the syntax I’ve learned to some use.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T16:10:45+00:00Added an answer on May 29, 2026 at 4:10 pm

    A Haskell program’s structure is surprisingly simple. You have a main function which does IO, and that’s about it. So the basics:

    module Main where
    
    addition a b = a + b
    
    main :: IO ()
    main = do let z = addition 5 3
              putStrLn $ "The result is: " ++ show z
    

    Now you can compile this into a simple program using something like:

    ghc --make Main.hs -o program
    

    and it should produce an executable called program.

    In general, programs are structured as mostly pure functions doing the actual computation coupled with discrete parts of the code dealing with the IO. (There are of course exceptions to this, but the general idea of writing as much pure code as possible is fairly universal.)

    Since almost everything is expressed as a bunch of pure functions, you do not pass variables between them–the functions communicate by passing arguments.

    The part of your code that does IO is anchored in main. In most cases, all your IO is going to go through main; even if you write IO actions separately and give them names, they will ultimately be executed starting from main.

    A “function group” in Haskell is called a “module”. You can have multiple modules, each in its own file:

    module Blarg (exportedFunction) where
    
    helper a b = ... -- this will *not* be exported
    exportedFunction a b = helper a b -- this *will* be exported
    

    Only the identifiers in the parentheses will actually be exported; the rest are hidden. If you do not include the parentheses at all, everything will be exported by default.

    Save this file as Blarg.hs. Now you can import it in Main:

    import Blarg
    

    Another useful way to group functions is where:

    complicatedFunction a b c = helper 0
      where helper count = ...
    

    This way helper is only in scope for complicatedFunction and also has access to a, b and c from complicatedFunction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Haskell's record syntax is considered by many to be a wart on an otherwise
There are many open sourced parser implementations available to us in Haskell. Parsec seems
I've written a small Haskell program to print the MD5 checksums of all files
I like haskell and many things connected with it as its type-engine, lot of
I am trying to convert a Haskell program to a Haskell GUI program, but
Ive come across some answers (here in SO) saying that Haskell has many dark
What does the term fac mean in Haskell? I've seen it on many occasions
If using Haskell as a library being called from my C program, what is
I am implementing a haskell program wich compares each line of a file with
I am implementing a haskell program which compares each line of a file with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.