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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:06:36+00:00 2026-05-30T03:06:36+00:00

I am working with Haskell for quite a while now, but I am far

  • 0

I am working with Haskell for quite a while now, but I am far from being an expert. But I see that the functional approach to programming suits me the best.

So far I am working on a project to calculate some serious stuff, like currents and potentials radiated from a given structure.

I followed the blog written by Conal Elliott (here is some more Linear Maps) which is very nice and fundamental.

Unfortunately, I am lacking a simple example 🙂

To be more precise, I have a curve

f:[0,1] in R -> R³
t -> a*e_y + 2*t*e_z

which is a simple straight line at (0,a,2*t).
When I want to calculate the derivative of f, e.g. for the length of the curve, I know the mathematical result, which is quite simple (0,0,2), but how do I accomplish this in Haskell, especially with the vector-space package?

I really want to use this library because of its functionality, it is exactly the approach I would have take too (but I am not that far ahead on the Haskell road)

What I have so far is this:

{-# LANGUAGE Rank2Types, TypeOperators, FlexibleContexts, TypeFamilies #-}
{-# OPTIONS_GHC -Wall #-}
import Numeric.GSL.Integration
import Data.VectorSpace
import Data.Basis
import Data.Cross
import Data.Derivative
import Data.LinearMap

type Vec3 s = Three s

prec :: Double
prec = 1E-9

f1 :: (Floating s, VectorSpace s, Scalar s ~ s) => s -> s
f1 = id

c1 :: Double -> Vec3 Double
c1  = \t -> linearCombo [((v 0 0 1),f1 t),(( v 0 1 0),2)]

derivC :: Double -> Vec3 (Double :> Double)
derivC t = c1 (pureD t)

It is the the actual implementation of the pureD function, so far nothing that I have tried works to get this snippet to compile. I get the following error:

tests.hs:26:12:
   Couldn't match expected type `Double :> Double'
               with actual type `Double'
   Expected type: Vec3 (Double :> Double)
     Actual type: Vec3 Double
   In the return type of a call of `c1'
   In the expression: c1 (pureD t)
Failed, modules loaded: none.

There is also a graphics library which uses vector-space and there is even an example on a torus, where pureD is used. I tried to deduce the example but I don’t see how I can map it to my problem.

Any help would be greatly appreciated.

Thanks in advance

PS: I cannot post all the links I’d like to, but am willing to provide

  • 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-30T03:06:37+00:00Added an answer on May 30, 2026 at 3:06 am

    That’s an interesting library.. Thanks for sharing.
    Although I don’t understand the concept of the library yet,
    how about this code:

    {-# LANGUAGE Rank2Types, TypeOperators, FlexibleContexts, TypeFamilies #-}
    module Main where
    
    import Data.LinearMap
    import Data.Maclaurin
    
    diff :: (Double :~> (Double,Double,Double) ) -> (Double :~> (Double,Double,Double))
    diff f = \x ->  (atBasis (derivative  (f x)) ())
    
    eval :: (Double :~> (Double,Double,Double)) -> Double -> (Double,Double,Double)
    eval f x = powVal (f x)        
    
    f :: Double :~> (Double,Double,Double)
    f x = tripleD (pureD 0,pureD 1,(2*idD) x)
    
    
    *Main> map (eval f) [0,0.2 .. 1]
    [(0.0,1.0,0.0),(0.0,1.0,0.4),(0.0,1.0,0.8),(0.0,1.0,1.2000000000000002),
     (0.0,1.0,1.6000000000000003),(0.0,1.0,2.0000000000000004)]
    
    *Main> map (eval (diff f)) [0,0.2 .. 1]
    [(0.0,0.0,2.0),(0.0,0.0,2.0),(0.0,0.0,2.0),(0.0,0.0,2.0),(0.0,0.0,2.0), 
     (0.0,0.0,2.0)]
    
    *Main> map (eval (diff $ diff f)) [0,0.2 .. 1]
     [(0.0,0.0,0.0),(0.0,0.0,0.0),(0.0,0.0,0.0),(0.0,0.0,0.0),(0.0,0.0,0.0),(0.0,0.0,0.0)]
    

    Try also g x = tripleD (pureD 0,idD x,(idD*idD) x) (which seem to represent the curve (0,x,x^2)).

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

Sidebar

Related Questions

It seems to me from my experimenting with Haskell, Erlang and Scheme that functional
I'm working on simple Haskell programme that fetches a JSON string from a server,
While working through Real World Haskell, I tried to complete the palindrome exercise using
I'm working on a dataflow-based optimization library written in Haskell. It now seems likely
Still working on my SHA1 implementation in Haskell. I've now got a working implementation
I was working with a Lisp dialect but also learning some Haskell as well.
Why in Haskell is not working range downto without step [7..1] => [] but
I am working through Graham Hutton's Programming in Haskell , and an exercise in
I'm working on a haskell web app using yesod that I eventually want to
I'm currently working on a Haskell project which automatically tests some functions based on

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.