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 7608531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:56:14+00:00 2026-05-31T00:56:14+00:00

Is there a difference between these two functions? ghct says: Prelude> :t (+1) (+1)

  • 0

Is there a difference between these two functions?

ghct says:

Prelude> :t (+1)
(+1) :: Num a => a -> a
Prelude> :t \x->x+1
\x->x+1 :: Num a => a -> a

But

When I used (+1) syntax in this piece of code:

data B = B { 
    pos :: Int, 
    cells :: [Int] 
} deriving (Show)

createB :: Int -> B
createB n = B 0 (take n $ repeat 0)

size :: B -> Int
size b = length $ cells b

get_curr :: B -> Int
get_curr b = (cells b) !! (pos b)

apply :: (Int -> Int) -> B -> B
apply f b = let n = pos b
                h = take n $ cells b       -- head
                t = drop (n + 1) $ cells b -- tail
                in B n $ h ++ [f (get_curr b)] ++ t

-- ...
eval :: [Char] -> StateT B IO ()
eval [] = return ()
eval (x:xs) = do
                b <- get

                put $ case x of
                        '+'         -> apply (+1) b
                        '-'         -> apply (-1) b
                        '>'         -> fwd b
                        '<'         -> back b
                        otherwise   -> b
                -- ...

prelude (as well as compiler) said:

> :load BrainFuck.hs 
[1 of 1] Compiling BrainFuck        ( BrainFuck.hs, interpreted )

BrainFuck.hs:49:40:
    No instance for (Num (Int -> Int))
      arising from the literal `1'
    Possible fix: add an instance declaration for (Num (Int -> Int))
    In the expression: 1
    In the first argument of `apply', namely `(- 1)'
    In the expression: apply (- 1) b
Failed, modules loaded: none.

What am I doing wrong?
sorry if code is not-so-cool (full source here: https://github.com/nskeip/bf/blob/a755b2d27292593d63fe1e63c2a6e01cebc73520/BrainFuck.hs)

  • 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-31T00:56:15+00:00Added an answer on May 31, 2026 at 12:56 am

    This code:

    (-1)
    

    … doesn’t mean the same thing as this code:

    \ x -> x - 1
    

    - is a special case in Haskell; it is the only prefix operator in the language. When you write (-1), you get “negative one” which is a number, and not “subtract one” which is a function.

    You should use subtract 1 to get what you need.

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

Sidebar

Related Questions

Is there any difference in functionality between these two types of complete-functions in Vimscript?
Is there any difference between these two functions? I mean in-terms of the result
What is the difference between these two functions? 1: $(document).ready(function myfunc() { function dosomething()
Is there any difference between these two LINQ statements: var query = from a
1)Is there any difference between these two keywords for the elements of collections??( Copy
When accessing values from an SqlDataReader is there a performance difference between these two:
Is there a difference (performance, overhead) between these two ways of merging data sets?
Is there difference between these two async JavaScript loading methods? <div class="g-plusone"></div> <script type="text/javascript">
Is there any difference between these two types of declarations performance-wise? local object =
In Javascript is there any difference between these two ways of adding a function

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.