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

  • SEARCH
  • Home
  • 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 237169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:24:14+00:00 2026-05-11T20:24:14+00:00

I came across the following definition as I try to learn Haskell using a

  • 0

I came across the following definition as I try to learn Haskell using a real project to drive it. I don’t understand what the exclamation mark in front of each argument means and my books didn’t seem to mention it.

data MidiMessage = MidiMessage !Int !MidiMessage
  • 1 1 Answer
  • 2 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-11T20:24:14+00:00Added an answer on May 11, 2026 at 8:24 pm

    It’s a strictness declaration. Basically, it means that it must be evaluated to what’s called “weak head normal form” when the data structure value is created. Let’s look at an example, so that we can see just what this means:

    data Foo = Foo Int Int !Int !(Maybe Int)
    
    f = Foo (2+2) (3+3) (4+4) (Just (5+5))
    

    The function f above, when evaluated, will return a “thunk”: that is, the code to execute to figure out its value. At that point, a Foo doesn’t even exist yet, just the code.

    But at some point someone may try to look inside it, probably through a pattern match:

    case f of
         Foo 0 _ _ _ -> "first arg is zero"
         _           -> "first arge is something else"
    

    This is going to execute enough code to do what it needs, and no more. So it will create a Foo with four parameters (because you can’t look inside it without it existing). The first, since we’re testing it, we need to evaluate all the way to 4, where we realize it doesn’t match.

    The second doesn’t need to be evaluated, because we’re not testing it. Thus, rather than 6 being stored in that memory location, we’ll just store the code for possible later evaluation, (3+3). That will turn into a 6 only if someone looks at it.

    The third parameter, however, has a ! in front of it, so is strictly evaluated: (4+4) is executed, and 8 is stored in that memory location.

    The fourth parameter is also strictly evaluated. But here’s where it gets a bit tricky: we’re evaluating not fully, but only to weak normal head form. This means that we figure out whether it’s Nothing or Just something, and store that, but we go no further. That means that we store not Just 10 but actually Just (5+5), leaving the thunk inside unevaluated. This is important to know, though I think that all the implications of this go rather beyond the scope of this question.

    You can annotate function arguments in the same way, if you enable the BangPatterns language extension:

    f x !y = x*y
    

    f (1+1) (2+2) will return the thunk (1+1)*4.

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

Sidebar

Related Questions

While reading a code I came across, the following definition and initialization of a
I came across this article on Code Project that talks about using an abstract
I came across the following markup in a JSP file in a legacy app
Today at work we came across the following code (some of you might recognize
Looking through some code I came across the following code trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); and I'd like
I'm trying to debug an application (under PostgreSQL) and came across the following error:
When refactoring away some #defines I came across declarations similar to the following in
Whilst trawling through some old code I came across something similar to the following:
I've been reading through the Linux kernel (specifically, 2.6.11). I came across the following
I'm trying to learn some Linq to XML stuff, and I came across the

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.