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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:49:26+00:00 2026-06-10T22:49:26+00:00

Possible Duplicate: Why is such a function definition not allowed in haskell? I would

  • 0

Possible Duplicate:
Why is such a function definition not allowed in haskell?

I would like to create a function flist that takes a function f as argument and returns another function whose argument will be a list but behaves exactly same as f.

For example:

let f x1 x2 x3 = x1+ x2 + x3

I want this behaviour

(flist f) [x1,x2,x3] = x1+x2+x3

When the list is not of length 3 it may behave in any way. flist should take care of any function (not only functions with 3 argument, i.e. if g x1 x2 x3 x4 = x1+x2+x3*x4, then (flist g) [x1,x2,x3,x4] = x1+x2+x3*x4 ).

I tried this,

flist f [] = f
flist f (x:xs) = flist (f x) xs

But it is not working. How do I achieve this? Can I use data types to do this?

  • 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-06-10T22:49:28+00:00Added an answer on June 10, 2026 at 10:49 pm

    With type families, you can get pretty far—but it surely is not for the faint of heart:

    {-# LANGUAGE FlexibleContexts  #-}
    {-# LANGUAGE FlexibleInstances #-}
    {-# LANGUAGE TypeFamilies      #-}
    
    class FList a where
      type Point a
      flist :: a -> [Point a] -> Point a
    
    instance FList (a -> a) where
      type Point (a -> a) = a
      flist f [x] = f x
    
    instance (FList (a -> b), a ~ Point (a -> b)) => FList (a -> (a -> b)) where
      type Point (a -> (a -> b)) = Point (a -> b)
      flist f (x : xs) = flist (f x) xs
    

    For your example, we get:

    > let f x y z = x + y + z
    > flist f [2, 3, 5]
    10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why is such a function definition not allowed in haskell? I'm a
Possible Duplicate: Find location of current m-file in Matlab I would like to write
Possible Duplicate: What are PHP nested functions for? PHP allows nested function declarations like
Possible Duplicate: “Least Astonishment” in Python: The Mutable Default Argument Consider the following function:
Possible Duplicate: Compare 2 dates with JavaScript I would like to have a Javascript
Possible Duplicate: Check that element is in DOM or not with jQuery? So I
Possible Duplicate: Calculate date/time difference in java how would a future date such as
Possible Duplicate: String with array structure to Array I have an array as such
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Python Ternary Operator If Python would support the (x ? a :

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.