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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:47:44+00:00 2026-05-27T11:47:44+00:00

We can use type synonym for function definitions, e.g. type FuncDef = Int ->

  • 0

We can use type synonym for function definitions, e.g.

type FuncDef = Int -> Int -> Int

This avoids us writing long function definition every time.

Use:

someFunc :: FuncDef -> Int

Instead of

someFunc :: (Int -> Int -> Int) -> Int

which is more readable and less code as well.

Simple algebraic data types are straight forward and easy to do pattern matching etc, e.g.

data AType = X | Y | Z Int
matchType :: AType -> Bool
matchType X = ..
matchType Y = ..
matchType (Z _) = ..

As I look more into Haskell data types, I found we can have function definition in data constructor when defining new type.

data MyType a b = X | Y (a -> b)

This puzzles me a bit and haven’t seen many examples of this around. In a way, the idea of high-order function where a function can take another function as argument is similar to this situation, except here it applies to data type. The Haskell wiki does not say much about “high-order data type definition”. I realise I may be getting all these terms wrong, so please correct me, and point me to more reading. I really want to see a concrete usage of this. Thanks!

matchMyType :: (MyType a b) -> Bool
matchMyType X = ..
matchMyType Y ?? = .. 
  • 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-27T11:47:45+00:00Added an answer on May 27, 2026 at 11:47 am

    You might use this kind of pattern in many situations. For example, if you want a function that transforms strings in various ways, you might have a data type like this (This is just an example that demonstrates the principle – don’t write code like this!):

    data StringTransformation =
      -- | Doesn't transform the string at all
      NoTransformation |
      -- | Takes the string and generates a suffix that should be appended
      Append (String -> String) |
      -- | Takes the string and generates a prefix that should be prepended
      Prepend (String -> String) |
      -- | Takes the string and transforms it arbitrarily to a new string
      Map (String -> String)
    

    Then, a program that uses this might look like:

    -- | Returns 'True' if the name is male
    isMaleName :: String -> Bool
    isMaleName = ...
    
    -- | Adds a title to a name, for example "John Smith" -> "Mr. John Smith"
    addTitle :: StringTransformation
    addTitle =
      PrependTransformation $ \ name ->
      if isMaleName name
      then "Mr. "
      else "Mrs. "
    
    -- Applies a string transformation to a 'String'.
    transformString :: StringTransformation -> String -> String
    transformString NoTransformation str = str
    transformString (Append f) str       = str ++ f str
    transformString (Prepend f) str      = f str ++ str
    transformString (Map f) str          = f str
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I use type as a name for a python function argument? def fun(name,
Can I use dynamic data type in WF 4.0? And if this is possible
I know that I can use the type string as: string someString = This
How can I use UIViewAnimationTransition type in one of UINavigation / TabBar transitions ?
To create a delegate from a method you can use the compile type-safe syntax:
I can use TypeDescriptor.AddAttributes to add an attribute to a type in runtime. How
In C#, you can use the implicit keyword to define an implicit user-defined type
Can I use yield return when the return type is an IGrouping<TKey, TElement> or
I can't use TryGetValue() from dictionary in linq expression with anonymous type. Dictionary<string, string>
When you declare a type parameter for the class, you can simply use 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.