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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:15:33+00:00 2026-05-28T11:15:33+00:00

I have defined a custom type as follows: — Atom reference number, x coordinate,

  • 0

I have defined a custom type as follows:

-- Atom reference number, x coordinate, y coordinate, z coordinate, element symbol, 
--      atom name, residue sequence number, amino acid abbreviation
type Atom = (Int, Double, Double, Double, Word8, ByteString, Int, ByteString)

I would like to gather all of the atoms with a certain residue sequence number nm.

This would be nice:

[x | x <- p, d == nm]
where
    (_, _, _, _, _, _, d, _) = x

where p is a list of atoms.

However, this does not work because I can not access the variable x outside of the list comprehension, nor can I think of a way to access a specific tuple value from inside the list comprehension.

Is there a tuple method I am missing, or should I be using a different data structure?

I know I could write a recursive function that unpacks and checks every tuple in the list p, but I am actually trying to use this nested inside an already recursive function, so I would rather not need to introduce that complexity.

  • 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-28T11:15:34+00:00Added an answer on May 28, 2026 at 11:15 am

    This works:

    [x | (_, _, _, _, _, _, d, _) <- p, d == nm]
    

    However, you should really define your own data type here. A three-element tuple is suspicious; an eight-element tuple is very bad news indeed. Tuples are difficult to work with and less type-safe than data types (if you represent two different kinds of data with two tuples with the same element types, they can be used interchangeably). Here’s how I’d write Atom as a record:

    data Point3D = Point3D Double Double Double
    
    data Atom = Atom
      { atomRef :: Int
      , atomPos :: Point3D
      , atomSymbol :: Word8
      , atomName :: ByteString
      , atomSeqNum :: Int
      , atomAcidAbbrev :: ByteString
      } deriving (Eq, Show)
    

    (The “atom” prefix is to avoid clashing with the names of fields in other records.)

    You can then write the list comprehension as follows:

    [x | x <- p, atomSeqNum x == nm]
    

    As a bonus, your definition of Atom becomes self-documenting, and you reap the benefits of increased type safety. Here’s how you’d create an Atom using this definition:

    myAtom = Atom
      { atomRef = ...
      , atomPos = ...
      , ... etc. ...
      }
    

    By the way, it’s probably a good idea to make some of the fields of these types strict, which can be done by putting an exclamation mark before the type of the field; this helps avoid space leaks from unevaluated thunks building up. For instance, since it doesn’t make much sense to evaluate a Point3D without also evaluating all its components, I would instead define Point3D as:

    data Point3D = Point3D !Double !Double !Double
    

    It would probably be a good idea to make all the fields of Atom strict too, although perhaps not all of them; for example, the ByteString fields should be left non-strict if they’re generated by the program, not always accessed and possibly large. On the other hand, if their values are read from a file, then they should probably be made strict.

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

Sidebar

Related Questions

I have an custom binding defined as follows: <customBinding> <binding name=binaryHttpBinding> <binaryMessageEncoding /> <httpTransport
Say I have defined a custom AdapterElement : ConfigurationElement with properties Type , Name
I have defined a custom file type with these lines: syn region SubSubtitle start=+=+
I have defined a custom list template type for SharePoint . I install it
I've defined a custom content type - news. I also have a menu item
I have defined a custom user type that works fine when used properties of
I have defined a custom edge and vertex type to use in an undirected
I am building a custom ,module with a custom content type. I have defined
I have defined a custom Sharepoint list for special attributes related to a software
I have defined a custom IPrincipal and custom IIdentity based on a website that

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.