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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:55:18+00:00 2026-05-26T00:55:18+00:00

data Test = [Int] | Int foobar :: Test -> Int What if I

  • 0
data Test = [Int] | Int

foobar :: Test -> Int

What if I wanted something like foobar [1,2,3] = 1 and foobar 1 = 1. In erlang it would be

foobar(X) when is_list(X) -> hd(X);
foobar(X) -> X.
  • 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-26T00:55:19+00:00Added an answer on May 26, 2026 at 12:55 am

    First of all, your data-declaration is invalid. In Haskell, you have to start a data-declaration with a data-constructor, that is later matched upon. For instance, your type Test would be written

    data Test = TLst [Int] | TInt Int
    

    Now you can simply match on the type-constructor; it’s field is a list or an int, depending on which constructor you match:

    foobar :: Test -> Int
    foobar (TLst (x:xs)) = x
    foobar (TLst [])     = error "empty list passed to foobar"
    foobar (TInt x)      = x
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
I would like to insert some data into an Access Database. DataTable dt =
Consider the following data source: declare @Test table (EmpId int, ProdId int, Sold int)
class Test:ICloneable { int a; Test() { a = 20; } public int Data
I'm pasting test data from a SQL results into my code. I'm using the
I'm creating test data for a Rails app. How do I define the value
I have some kind of test data and want to create a unit test
I want to generate some test data so for each row in a table
Is there any tool to generate test data based on specific requirements? e.g. Size,
I'm trying to use fixtures to add more complex test data in order to

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.